summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)