X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Flib.c;h=7597742cf8e0cf1b5acb92c7eaeac883f1ef1a0e;hb=a0bdec284624820feb0a96a06c0c38e2f07d5e4e;hp=1ed3837bd6549fbd400d361c87f7177e48218576;hpb=2b7079eed24448e15f7200c96efc23f22a2e4db9;p=simgear.git diff --git a/simgear/nasal/lib.c b/simgear/nasal/lib.c index 1ed3837b..7597742c 100644 --- a/simgear/nasal/lib.c +++ b/simgear/nasal/lib.c @@ -1,14 +1,14 @@ #include "nasal.h" -#ifndef _MSC_VER // 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++; return s - s0; } -#endif static naRef size(naContext c, naRef args) { @@ -46,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