summaryrefslogtreecommitdiff
path: root/functions.cpp
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-09-10 21:42:12 +0200
committertomsmeding <hallo@tomsmeding.nl>2015-09-10 21:42:12 +0200
commit78a145a5bb77b73f5fbefb0efa2d188926eb55ef (patch)
tree345a7e59216d2a61a3668b9eea412f1018b95686 /functions.cpp
parent0a2c7d3ccb5621150d827643bc2c196f7f8db664 (diff)
Add arrset
Diffstat (limited to 'functions.cpp')
-rw-r--r--functions.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/functions.cpp b/functions.cpp
index 792e2cc..f4beeb9 100644
--- a/functions.cpp
+++ b/functions.cpp
@@ -421,6 +421,19 @@ unordered_map<string,function<void(vector<Stackitem>&,unordered_map<string,Stack
S.push_back(S.back().arrval[idx.intval]);
}},
//leaves the array on the stack
+ {"arrset",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
+ BUILTIN_GUARD_STACKSIZE("arrset",3)
+ const Stackitem idx=move(S.back()); S.pop_back();
+ Stackitem val=move(S.back()); S.pop_back();
+ if(idx.type!=SIT_INT)
+ throw string("Second argument to 'arrset' not a number");
+ if(S.back().type!=SIT_ARR)
+ throw string("Top of stack is not an array in builtin 'arrset'");
+ if(idx.intval<0||idx.intval>=S.back().arrval.size())
+ throw string("Index argument to 'arrset' out of range");
+ S.back().arrval[idx.intval]=move(val);
+ }},
+ //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)