summaryrefslogtreecommitdiff
path: root/functions.cpp
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-09-10 19:56:51 +0200
committertomsmeding <hallo@tomsmeding.nl>2015-09-10 19:56:51 +0200
commit3e22583f8596fd8bb2b1e8f651c38f5a898a6155 (patch)
tree60d74e8e36f19135c23e09bd375ac8666d8f3413 /functions.cpp
parent7f7adef5b160e473dba8340bba1cd9b0bffc15d6 (diff)
arrpushf, arrpopf, error
Diffstat (limited to 'functions.cpp')
-rw-r--r--functions.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/functions.cpp b/functions.cpp
index bd718f8..792e2cc 100644
--- a/functions.cpp
+++ b/functions.cpp
@@ -436,12 +436,28 @@ unordered_map<string,function<void(vector<Stackitem>&,unordered_map<string,Stack
S.pop_back();
}},
//leaves the array on the stack, obviously
+ {"arrpushf",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
+ BUILTIN_GUARD_STACKSIZE("arrpushf",2)
+ Stackitem &arrref=S[S.size()-2];
+ if(arrref.type!=SIT_ARR)
+ throw string("Top of stack is not an array in builtin 'arrpushf'");
+ arrref.arrval.insert(arrref.arrval.begin(),move(S.back()));
+ S.pop_back();
+ }},
+ //leaves the array on the stack, obviously
{"arrpop",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
BUILTIN_GUARD_STACKSIZE("arrpop",1)
if(S.back().type!=SIT_ARR)
throw string("Top of stack is not an array in builtin 'arrpop'");
S.back().arrval.pop_back();
}},
+ //leaves the array on the stack, obviously
+ {"arrpopf",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
+ BUILTIN_GUARD_STACKSIZE("arrpopf",1)
+ if(S.back().type!=SIT_ARR)
+ throw string("Top of stack is not an array in builtin 'arrpopf'");
+ S.back().arrval.erase(S.back().arrval.begin());
+ }},
{"rand",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
BUILTIN_GUARD_STACKSIZE("rand",0)
assert(RAND_MAX==0x7fffffff);
@@ -474,6 +490,10 @@ unordered_map<string,function<void(vector<Stackitem>&,unordered_map<string,Stack
}
cerr<<endl;
}},
+ {"error",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
+ BUILTIN_GUARD_STACKSIZE("error",0)
+ exit(1); //STUB IMPLEMENTATION
+ }},
{"exit",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
BUILTIN_GUARD_STACKSIZE("exit",0)
exit(0);