diff --git a/README.md b/README.md index f5ed272..8cee72f 100644 --- a/README.md +++ b/README.md @@ -733,6 +733,12 @@ This only works on strings: #### Built-in functions +##### Pair methods + +`name(pair)`: returns the name (first element) of a pair + +`value(pair)`: returns the value (second element) of a pair + ##### List methods `len(list)`: returns length of the list diff --git a/stdlib/functions.lua b/stdlib/functions.lua index dce5643..c270cc9 100644 --- a/stdlib/functions.lua +++ b/stdlib/functions.lua @@ -267,6 +267,23 @@ functions = { end } }, + -- pair methods + name = { + { + arity = 1, types = { "pair" }, mode = "raw", + value = function(a) + return a.value[1] + end + } + }, + value = { + { + arity = 1, types = { "pair" }, mode = "raw", + value = function(a) + return a.value[2] + end + } + }, -- list methods len = { {