From b93061143ccbc7ded2275604cdbc4c7b3e90ed1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Sun, 25 Apr 2021 18:46:22 +0200 Subject: [PATCH] Add name and value pair methods --- README.md | 6 ++++++ stdlib/functions.lua | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) 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 = { {