From 74151599d4107055c6d8ecef05ad9cbd6b2045bb Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 10 Sep 2015 15:50:21 +0200 Subject: more array functions --- functions.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'functions.cpp') diff --git a/functions.cpp b/functions.cpp index 03b8805..261405e 100644 --- a/functions.cpp +++ b/functions.cpp @@ -420,6 +420,28 @@ unordered_map&,unordered_map &S,unordered_map &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 &S,unordered_map &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 &S,unordered_map &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 &S,unordered_map &variables){ BUILTIN_GUARD_STACKSIZE("rand",0) assert(RAND_MAX==0x7fffffff); -- cgit v1.2.3-70-g09d2