summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-09-10 15:38:09 +0200
committertomsmeding <hallo@tomsmeding.nl>2015-09-10 15:38:09 +0200
commitd95a42c7b299e43bfe026c0a2e8233679ccfc01c (patch)
tree22392501a3924de7962343f5f772082dcd9153e2
parent0711be4f145b3d74bc90658dd71d186716e6a72c (diff)
add mkarrayp
-rw-r--r--functions.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/functions.cpp b/functions.cpp
index dacd194..03b8805 100644
--- a/functions.cpp
+++ b/functions.cpp
@@ -394,6 +394,20 @@ unordered_map<string,function<void(vector<Stackitem>&,unordered_map<string,Stack
BUILTIN_GUARD_STACKSIZE("mkarray",0)
S.emplace_back(Stackitem(vector<Stackitem>()));
}},
+ //mkarray prefill
+ {"mkarrayp",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
+ BUILTIN_GUARD_STACKSIZE("mkarrayp",1)
+ const Stackitem nitems=move(S.back()); S.pop_back();
+ if(nitems.type!=SIT_INT)throw string("Argument to 'mkarrayp' not a number");
+ if(nitems.intval<0)throw string("Negative argument to 'mkarrayp'");
+ BUILTIN_GUARD_STACKSIZE("mkarrayp: prefill",nitems.intval);
+ Stackitem res((vector<Stackitem>()));
+ res.arrval.reserve(nitems.intval);
+ const int sz=S.size();
+ for(int i=sz-nitems.intval;i<sz;i++)res.arrval.push_back(move(S[i]));
+ S.erase(S.end()-nitems.intval,S.end());
+ S.push_back(move(res));
+ }},
//leaves the array on the stack
{"arridx",[](vector<Stackitem> &S,unordered_map<string,Stackitem> &variables){
BUILTIN_GUARD_STACKSIZE("arridx",2)