summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--functions.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/functions.cpp b/functions.cpp
index 03b8805..261405e 100644
--- a/functions.cpp
+++ b/functions.cpp
@@ -420,6 +420,28 @@ unordered_map<string,function<void(vector<Stackitem>&,unordered_map<string,Stack
throw string("Argument to 'arridx' out of range");
S.push_back(S.back().arrval[idx.intval]);
}},
+ //leaves the array on the stack
+ {"arrlen",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
+ BUILTIN_GUARD_STACKSIZE("arrlen",1)
+ if(S.back().type!=SIT_ARR)
+ throw string("Top of stack is not an array in builtin 'arrlen'");
+ S.emplace_back(S.back().arrval.size());
+ }},
+ //leaves the array on the stack, obviously
+ {"push",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
+ BUILTIN_GUARD_STACKSIZE("push",2)
+ if(S[S.size()-2].type!=SIT_ARR)
+ throw string("Top of stack is not an array in builtin 'push'");
+ S[S.size()-2].arrval.push_back(move(S.back()));
+ S.pop_back();
+ }},
+ //leaves the array on the stack, obviously
+ {"pop",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
+ BUILTIN_GUARD_STACKSIZE("pop",1)
+ if(S.back().type!=SIT_ARR)
+ throw string("Top of stack is not an array in builtin 'pop'");
+ S.back().arrval.pop_back();
+ }},
{"rand",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
BUILTIN_GUARD_STACKSIZE("rand",0)
assert(RAND_MAX==0x7fffffff);