summaryrefslogtreecommitdiff
path: root/functions.cpp
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-09-10 15:50:21 +0200
committertomsmeding <hallo@tomsmeding.nl>2015-09-10 15:50:21 +0200
commit74151599d4107055c6d8ecef05ad9cbd6b2045bb (patch)
treebd463fd2bcf2eeb82b4b92bc32e2486b54985b2c /functions.cpp
parentd95a42c7b299e43bfe026c0a2e8233679ccfc01c (diff)
more array functions
Diffstat (limited to 'functions.cpp')
-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);