X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Flib.c;h=7597742cf8e0cf1b5acb92c7eaeac883f1ef1a0e;hb=a0bdec284624820feb0a96a06c0c38e2f07d5e4e;hp=440faaa6a4277ed477cd5389115310b7893d2a2f;hpb=1786692406214447db12b9d5af5364582af23d3b;p=simgear.git diff --git a/simgear/nasal/lib.c b/simgear/nasal/lib.c index 440faaa6..7597742c 100644 --- a/simgear/nasal/lib.c +++ b/simgear/nasal/lib.c @@ -1,7 +1,9 @@ #include "nasal.h" // No need to include just for this: -static int strlen(char* s) +// It needs a funny name because MSVC wants to treat "strlen" as a +// special symbol. Ugh... +static int StrLen(char* s) { char* s0 = s; while(*s) s++; @@ -44,6 +46,33 @@ static naRef pop(naContext c, naRef args) return naVec_removelast(v); } +static naRef setsize(naContext c, naRef args) +{ + naRef v = naVec_get(args, 0); + int sz = (int)naNumValue(naVec_get(args, 1)).num; + if(!naIsVector(v)) return naNil(); + naVec_setsize(v, sz); + return v; +} + +static naRef subvec(naContext c, naRef args) +{ + int i; + naRef nlen, result, v = naVec_get(args, 0); + int len = 0, start = (int)naNumValue(naVec_get(args, 1)).num; + nlen = naNumValue(naVec_get(args, 2)); + if(!naIsNil(nlen)) + len = (int)naNumValue(naVec_get(args, 2)).num; + if(!naIsVector(v) || start < 0 || start >= naVec_size(v) || len < 0) + return naNil(); + if(len == 0 || len > naVec_size(v) - start) len = naVec_size(v) - start; + result = naNewVector(c); + naVec_setsize(result, len); + for(i=0; i