sqstdsystem.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /* see copyright notice in squirrel.h */
  2. #include <squirrel.h>
  3. #include <string.h>
  4. #include "sqstdblobimpl.h"
  5. #include <time.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #ifdef _WIN32_WCE
  9. #include "celibc.h"
  10. #else
  11. #include <signal.h>
  12. #endif
  13. #include <sqstdsystem.h>
  14. #ifdef _WIN32
  15. #include <windows.h>
  16. #else
  17. #include <unistd.h>
  18. #endif
  19. #ifdef SQUNICODE
  20. #include <wchar.h>
  21. #define scgetenv _wgetenv
  22. #define scsystem _wsystem
  23. #define scasctime _wasctime
  24. #define scstrftime _wstrftime
  25. #define scremove _wremove
  26. #define screname _wrename
  27. #else
  28. #define scgetenv getenv
  29. #define scsystem system
  30. #define scasctime asctime
  31. #define scstrftime strftime
  32. #define scremove remove
  33. #define screname rename
  34. #endif
  35. SQ_OPT_STRING_STRLEN();
  36. #ifdef WITH_UUID
  37. #ifdef _WIN32
  38. #include <Rpc.h> //uuid
  39. #else
  40. #include <uuid/uuid.h>
  41. #endif
  42. static SQRESULT _system_getuuid(HSQUIRRELVM v)
  43. {
  44. #ifdef _WIN32
  45. UUID uuid;
  46. UuidCreate ( &uuid );
  47. UuidToStringA ( &uuid, &str );
  48. sq_pushstring(v,s,-1);
  49. RpcStringFreeA ( &str );
  50. #else
  51. uuid_t uuid;
  52. uuid_generate_random ( uuid );
  53. char s[37];
  54. uuid_unparse ( uuid, s );
  55. sq_pushstring(v,s,-1);
  56. #endif
  57. return 1;
  58. }
  59. #endif
  60. static SQRESULT _system_getenv(HSQUIRRELVM v)
  61. {
  62. const SQChar *s;
  63. if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){
  64. sq_pushstring(v,scgetenv(s),-1);
  65. return 1;
  66. }
  67. return 0;
  68. }
  69. static SQRESULT _system_system(HSQUIRRELVM v)
  70. {
  71. const SQChar *s;
  72. if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){
  73. sq_pushinteger(v,scsystem(s));
  74. return 1;
  75. }
  76. return sq_throwerror(v,_SC("wrong param"));
  77. }
  78. static SQRESULT _system_clock(HSQUIRRELVM v)
  79. {
  80. sq_pushfloat(v,((SQFloat)clock())/(SQFloat)CLOCKS_PER_SEC);
  81. return 1;
  82. }
  83. /*
  84. static SQRESULT _system_time(HSQUIRRELVM v)
  85. {
  86. time_t t;
  87. time(&t);
  88. sq_pushinteger(v,*((SQInteger *)&t));
  89. return 1;
  90. }
  91. */
  92. static SQRESULT get_int_field (HSQUIRRELVM v, const SQChar *key, int dflt) {
  93. SQInteger res;
  94. SQObjectType stype;
  95. sq_pushstring(v, key, -1);
  96. if(sq_get(v, -2) == SQ_OK){
  97. stype = sq_gettype(v, -1);
  98. if (stype & SQOBJECT_NUMERIC){
  99. sq_getinteger(v, -1, &res);
  100. sq_poptop(v);
  101. return res;
  102. }
  103. sq_poptop(v);
  104. }
  105. if(dflt < 0) return sq_throwerror(v, _SC("field %s is missing"), key);
  106. return dflt;
  107. }
  108. static SQRESULT _system_time(HSQUIRRELVM v) {
  109. time_t t;
  110. if (sq_gettop(v) == 1) /* called without args? */
  111. t = time(NULL); /* get current time */
  112. else {
  113. struct tm ts;
  114. if(sq_gettype(v, 2) != OT_TABLE)
  115. return sq_throwerror(v, _SC("table expected as parameter but got (%s)"), sq_gettypename(v, 2));
  116. sq_settop(v, 2); /* make sure table is at the top */
  117. SQInteger rc = get_int_field(v, _SC("sec"), 0);
  118. if(rc == SQ_ERROR) return rc;
  119. else ts.tm_sec = rc;
  120. rc = get_int_field(v, _SC("min"), 0);
  121. if(rc == SQ_ERROR) return rc;
  122. else ts.tm_min = rc;
  123. rc = get_int_field(v, _SC("hour"), 12);
  124. if(rc == SQ_ERROR) return rc;
  125. else ts.tm_hour = rc;
  126. rc = get_int_field(v, _SC("day"), -1);
  127. if(rc == SQ_ERROR) return rc;
  128. else ts.tm_mday = rc;
  129. rc = get_int_field(v, _SC("month"), -1);
  130. if(rc == SQ_ERROR) return rc;
  131. else ts.tm_mon = rc;
  132. rc = get_int_field(v, _SC("year"), -1);
  133. if(rc == SQ_ERROR) return rc;
  134. else ts.tm_year = rc - 1900;
  135. SQBool isdst = SQTrue;
  136. sq_pushstring(v, _SC("isdst"), -1);
  137. if(sq_get(v, 2) == SQ_OK){
  138. if(sq_getbool(v, -1, &isdst) == SQ_OK){
  139. ts.tm_isdst = isdst;
  140. }
  141. sq_poptop(v);
  142. }
  143. ts.tm_isdst = isdst;
  144. t = mktime(&ts);
  145. }
  146. if (t == (time_t)(-1))
  147. sq_pushnull(v);
  148. else sq_pushinteger(v,(SQInteger)t);
  149. return 1;
  150. }
  151. static SQRESULT _system_difftime (HSQUIRRELVM v) {
  152. SQ_FUNC_VARS(v);
  153. SQ_GET_FLOAT(v, 2, t1);
  154. SQ_OPT_FLOAT(v, 3, t2, 0);
  155. sq_pushfloat(v, difftime( (time_t)t1, (time_t)t2));
  156. return 1;
  157. }
  158. static SQRESULT _system_remove(HSQUIRRELVM v)
  159. {
  160. const SQChar *s;
  161. sq_getstring(v,2,&s);
  162. if(scremove(s)==-1)
  163. return sq_throwerror(v,_SC("remove() failed"));
  164. return 0;
  165. }
  166. static SQRESULT _system_rename(HSQUIRRELVM v)
  167. {
  168. const SQChar *oldn,*newn;
  169. sq_getstring(v,2,&oldn);
  170. sq_getstring(v,3,&newn);
  171. if(screname(oldn,newn)==-1)
  172. return sq_throwerror(v,_SC("rename() failed"));
  173. return 0;
  174. }
  175. static void _set_integer_slot(HSQUIRRELVM v,const SQChar *name,SQInteger val)
  176. {
  177. sq_pushstring(v,name,-1);
  178. sq_pushinteger(v,val);
  179. sq_rawset(v,-3);
  180. }
  181. static SQRESULT _system_date(HSQUIRRELVM v)
  182. {
  183. SQ_FUNC_VARS(v);
  184. SQ_OPT_STRING(v, 2, arg_format, _SC("%c"));
  185. SQ_OPT_FLOAT(v, 3, arg_time, time(NULL));
  186. time_t t = (time_t)arg_time;
  187. struct tm *stm;
  188. if (*arg_format == _SC('!')) { /* UTC? */
  189. stm = gmtime(&t);
  190. arg_format++; /* skip `!' */
  191. }
  192. else
  193. stm = localtime(&t);
  194. if (stm == NULL) /* invalid date? */
  195. sq_pushnull(v);
  196. else if (scstrcmp(arg_format, _SC("*t")) == 0) {
  197. sq_newtableex(v, 9); /* 9 = number of fields */
  198. _set_integer_slot(v, _SC("sec"), stm->tm_sec);
  199. _set_integer_slot(v, _SC("min"), stm->tm_min);
  200. _set_integer_slot(v, _SC("hour"), stm->tm_hour);
  201. _set_integer_slot(v, _SC("day"), stm->tm_mday);
  202. _set_integer_slot(v, _SC("month"), stm->tm_mon);
  203. _set_integer_slot(v, _SC("year"), stm->tm_year+1900);
  204. _set_integer_slot(v, _SC("wday"), stm->tm_wday);
  205. _set_integer_slot(v, _SC("yday"), stm->tm_yday);
  206. sq_pushliteral(v, _SC("isdst"));
  207. sq_pushbool(v, stm->tm_isdst);
  208. sq_rawset(v, -3);
  209. }
  210. else {
  211. SQChar cc[3];
  212. SQBlob b(0, BLOB_BUFSIZE);
  213. cc[0] = _SC('%'); cc[2] = _SC('\0');
  214. for (; *arg_format; arg_format++) {
  215. if (*arg_format != _SC('%') || *(arg_format + 1) == _SC('\0')) /* no conversion specifier? */
  216. b.WriteChar(*arg_format);
  217. else {
  218. size_t reslen;
  219. SQChar buff[200]; /* should be big enough for any conversion result */
  220. cc[1] = *(++arg_format);
  221. reslen = scstrftime(buff, sizeof(buff)/sizeof(SQChar), cc, stm);
  222. b.Write(buff, reslen);
  223. }
  224. }
  225. sq_pushstring(v, (const SQChar*)b.GetBuf(), b.Len());
  226. }
  227. return 1;
  228. }
  229. static SQRESULT _system_exit (HSQUIRRELVM v) {
  230. SQRESULT status = 0;
  231. SQ_FUNC_VARS(v);
  232. if(_top_ > 1){
  233. SQObjectType ptype = sq_gettype(v, 1);
  234. if (ptype == OT_BOOL){
  235. SQ_GET_BOOL(v,2, b);
  236. status = b ? EXIT_SUCCESS : EXIT_FAILURE;
  237. }
  238. else
  239. sq_getinteger(v, 2, &status);
  240. SQ_OPT_BOOL(v, 3, bclose, false);
  241. if (bclose) sq_close(v);
  242. }
  243. exit(status);
  244. }
  245. #if defined(SC_USE_MKSTEMP)
  246. #include <unistd.h>
  247. #define SQ_TMPNAMBUFSIZE 32
  248. #define sq_tmpnam(b,e) { \
  249. strcpy(b, "/tmp/lua_XXXXXX"); \
  250. e = mkstemp(b); \
  251. if (e != -1) close(e); \
  252. e = (e == -1); }
  253. #else
  254. #define SQ_TMPNAMBUFSIZE L_tmpnam
  255. #define sq_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
  256. #endif
  257. static SQRESULT _system_tmpname (HSQUIRRELVM v) {
  258. SQChar buff[SQ_TMPNAMBUFSIZE];
  259. int err;
  260. sq_tmpnam(buff, err);
  261. if (err)
  262. return sq_throwerror(v, _SC("unable to generate a unique filename"));
  263. sq_pushstring(v, buff, -1);
  264. return 1;
  265. }
  266. #ifndef _WIN32_WCE
  267. #include <locale.h>
  268. #endif
  269. static SQRESULT _system_setlocale (HSQUIRRELVM v) {
  270. #ifndef _WIN32_WCE
  271. static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
  272. LC_NUMERIC, LC_TIME};
  273. static const SQChar *const catnames[] = {_SC("all"), _SC("collate"), _SC("ctype"),
  274. _SC("monetary"), _SC("numeric"), _SC("time"), NULL};
  275. SQ_FUNC_VARS(v);
  276. SQ_OPT_STRING(v, 2, l, NULL);
  277. SQ_OPT_STRING(v, 3, name, _SC("all"));
  278. for (int i=0; catnames[i]; i++)
  279. if (scstrcmp(catnames[i], name) == 0){
  280. sq_pushstring(v, setlocale(cat[i], l), -1);
  281. return 1;
  282. }
  283. return sq_throwerror(v, _SC("invalid option %s for param %d"), name, 3);
  284. #else
  285. return 0;
  286. #endif
  287. }
  288. /*-------------------------------------------------------------------------*\
  289. * Sleep for n miliseconds.
  290. \*-------------------------------------------------------------------------*/
  291. static SQRESULT _system_sleep(HSQUIRRELVM v)
  292. {
  293. SQ_FUNC_VARS_NO_TOP(v);
  294. SQ_GET_INTEGER(v, 2, n);
  295. #ifdef _WIN32
  296. Sleep((int)n);
  297. #else
  298. usleep((n)*1000);
  299. #endif
  300. return 0;
  301. }
  302. #ifndef _WIN32_WCE
  303. #include <sys/timeb.h>
  304. int GetMilliCount()
  305. {
  306. // Something like GetTickCount but portable
  307. // It rolls over every ~ 12.1 days (0x100000/24/60/60)
  308. // Use GetMilliSpan to correct for rollover
  309. timeb tb;
  310. ftime( &tb );
  311. int nCount = tb.millitm + (tb.time & 0xfffff) * 1000;
  312. return nCount;
  313. }
  314. int GetMilliSpan( int nTimeStart )
  315. {
  316. int nSpan = GetMilliCount() - nTimeStart;
  317. if ( nSpan < 0 )
  318. nSpan += 0x100000 * 1000;
  319. return nSpan;
  320. }
  321. static SQRESULT _system_getmillicount (HSQUIRRELVM v) {
  322. sq_pushinteger(v, GetMilliCount());
  323. return 1;
  324. }
  325. static SQRESULT _system_getmillispan (HSQUIRRELVM v) {
  326. SQ_FUNC_VARS_NO_TOP(v);
  327. SQ_GET_INTEGER(v, 2, nTimeStart);
  328. sq_pushinteger(v, GetMilliSpan(nTimeStart));
  329. return 1;
  330. }
  331. #endif
  332. #ifdef USE_SIGNAL_HANDLER
  333. struct sq_signal_list
  334. {
  335. const char *name; /* name of the signal */
  336. int sig; /* the signal */
  337. };
  338. static const struct sq_signal_list sq_signals_list[] = {
  339. /* ANSI C signals */
  340. #ifdef SIGABRT
  341. {"SIGABRT", SIGABRT},
  342. #endif
  343. #ifdef SIGFPE
  344. {"SIGFPE", SIGFPE},
  345. #endif
  346. #ifdef SIGILL
  347. {"SIGILL", SIGILL},
  348. #endif
  349. #ifdef SIGINT
  350. {"SIGINT", SIGINT},
  351. #endif
  352. #ifdef SIGSEGV
  353. {"SIGSEGV", SIGSEGV},
  354. #endif
  355. #ifdef SIGTERM
  356. {"SIGTERM", SIGTERM},
  357. #endif
  358. /* posix signals */
  359. #ifdef SIGHUP
  360. {"SIGHUP", SIGHUP},
  361. #endif
  362. #ifdef SIGQUIT
  363. {"SIGQUIT", SIGQUIT},
  364. #endif
  365. #ifdef SIGTRAP
  366. {"SIGTRAP", SIGTRAP},
  367. #endif
  368. #ifdef SIGKILL
  369. {"SIGKILL", SIGKILL},
  370. #endif
  371. #ifdef SIGUSR1
  372. {"SIGUSR1", SIGUSR1},
  373. #endif
  374. #ifdef SIGUSR2
  375. {"SIGUSR2", SIGUSR2},
  376. #endif
  377. #ifdef SIGPIPE
  378. {"SIGPIPE", SIGPIPE},
  379. #endif
  380. #ifdef SIGALRM
  381. {"SIGALRM", SIGALRM},
  382. #endif
  383. #ifdef SIGCHLD
  384. {"SIGCHLD", SIGCHLD},
  385. #endif
  386. #ifdef SIGCONT
  387. {"SIGCONT", SIGCONT},
  388. #endif
  389. #ifdef SIGSTOP
  390. {"SIGSTOP", SIGSTOP},
  391. #endif
  392. #ifdef SIGTTIN
  393. {"SIGTTIN", SIGTTIN},
  394. #endif
  395. #ifdef SIGTTOU
  396. {"SIGTTOU", SIGTTOU},
  397. #endif
  398. /* some BSD signals */
  399. #ifdef SIGIOT
  400. {"SIGIOT", SIGIOT},
  401. #endif
  402. #ifdef SIGBUS
  403. {"SIGBUS", SIGBUS},
  404. #endif
  405. #ifdef SIGCLD
  406. {"SIGCLD", SIGCLD},
  407. #endif
  408. #ifdef SIGURG
  409. {"SIGURG", SIGURG},
  410. #endif
  411. #ifdef SIGXCPU
  412. {"SIGXCPU", SIGXCPU},
  413. #endif
  414. #ifdef SIGXFSZ
  415. {"SIGXFSZ", SIGXFSZ},
  416. #endif
  417. #ifdef SIGVTALRM
  418. {"SIGVTALRM", SIGVTALRM},
  419. #endif
  420. #ifdef SIGPROF
  421. {"SIGPROF", SIGPROF},
  422. #endif
  423. #ifdef SIGWINCH
  424. {"SIGWINCH", SIGWINCH},
  425. #endif
  426. #ifdef SIGPOLL
  427. {"SIGPOLL", SIGPOLL},
  428. #endif
  429. #ifdef SIGIO
  430. {"SIGIO", SIGIO},
  431. #endif
  432. /* add odd signals */
  433. #ifdef SIGSTKFLT
  434. {"SIGSTKFLT", SIGSTKFLT}, /* stack fault */
  435. #endif
  436. #ifdef SIGSYS
  437. {"SIGSYS", SIGSYS},
  438. #endif
  439. {NULL, 0}
  440. };
  441. static int _signal_received = 0;
  442. static void sq_sig_handle(int sig)
  443. {
  444. _signal_received = sig;
  445. }
  446. static SQRESULT _system_set_signal_received (HSQUIRRELVM v) {
  447. SQ_FUNC_VARS_NO_TOP(v);
  448. SQ_GET_INTEGER(v, 2, nvalue);
  449. _signal_received = nvalue;
  450. return SQ_OK;
  451. }
  452. static SQRESULT _system_get_signal_received (HSQUIRRELVM v) {
  453. sq_pushinteger(v, _signal_received);
  454. return 1;
  455. }
  456. static SQRESULT _system_signal_str2int (HSQUIRRELVM v) {
  457. SQ_FUNC_VARS_NO_TOP(v);
  458. SQ_GET_STRING(v, 2, signame);
  459. int sig = 0;
  460. for(int i=0, len = sizeof(sq_signals_list)/sizeof(sq_signal_list); i < len; ++i){
  461. if(strcmp(sq_signals_list[i].name, signame) == 0){
  462. sig = sq_signals_list[i].sig;
  463. break;
  464. }
  465. }
  466. if(sig) {
  467. sq_pushinteger(v, sig);
  468. return 1;
  469. }
  470. return sq_throwerror(v, _SC("invalid signal (%s)"), signame);
  471. }
  472. static SQRESULT _system_signal_int2str (HSQUIRRELVM v) {
  473. SQ_FUNC_VARS_NO_TOP(v);
  474. SQ_GET_INTEGER(v, 2, sig);
  475. const char *signame = NULL;
  476. for(int i=0, len = sizeof(sq_signals_list)/sizeof(sq_signal_list); i < len; ++i){
  477. if(sq_signals_list[i].sig == sig){
  478. signame = sq_signals_list[i].name;
  479. break;
  480. }
  481. }
  482. if(signame) {
  483. sq_pushstring(v, signame, -1);
  484. return 1;
  485. }
  486. return sq_throwerror(v, _SC("invalid signal (%d)"), sig);
  487. }
  488. static int _get_signal(HSQUIRRELVM v)
  489. {
  490. SQ_FUNC_VARS_NO_TOP(v);
  491. switch(sq_gettype(v, 2)){
  492. case OT_INTEGER:{
  493. SQ_GET_INTEGER(v, 2, iparam);
  494. return iparam;
  495. }
  496. break;
  497. case OT_STRING:{
  498. int sig = 0;
  499. SQ_GET_STRING(v, 2, signame);
  500. for(int i=0, len = sizeof(sq_signals_list)/sizeof(sq_signal_list); i < len; ++i){
  501. if(strcmp(sq_signals_list[i].name, signame) == 0){
  502. sig = sq_signals_list[i].sig;
  503. break;
  504. }
  505. }
  506. if(sig) return sig;
  507. else return sq_throwerror(v, _SC("invalid signal (%s)"), signame);
  508. }
  509. break;
  510. }
  511. return sq_throwerror(v, _SC("invalid paramter (%s)"), sq_gettypename(v, 2));
  512. }
  513. static SQRESULT _system_signal(HSQUIRRELVM v)
  514. {
  515. int sig = _get_signal(v);
  516. if(sig > 0) {
  517. sq_pushbool(v, signal(sig, sq_sig_handle) != SIG_ERR);
  518. return 1;
  519. }
  520. return sig;
  521. }
  522. static SQRESULT _system_raise(HSQUIRRELVM v)
  523. {
  524. int sig = _get_signal(v);
  525. if(sig > 0) {
  526. sq_pushbool(v, raise(sig) == 0);
  527. return 1;
  528. }
  529. return sig;
  530. }
  531. #endif
  532. #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_system_##name,nparams,pmask}
  533. static SQRegFunction systemlib_funcs[]={
  534. _DECL_FUNC(getenv,2,_SC(".s")),
  535. _DECL_FUNC(system,2,_SC(".s")),
  536. _DECL_FUNC(clock,0,NULL),
  537. _DECL_FUNC(remove,2,_SC(".s")),
  538. _DECL_FUNC(rename,3,_SC(".ss")),
  539. _DECL_FUNC(date,-1,_SC(".sn")),
  540. _DECL_FUNC(tmpname,1,_SC(".")),
  541. _DECL_FUNC(setlocale,-1,_SC(".ss")),
  542. _DECL_FUNC(time,-1,_SC(".t")),
  543. _DECL_FUNC(difftime,-2,_SC(".nn")),
  544. _DECL_FUNC(exit, -1,_SC(". b|i b")),
  545. _DECL_FUNC(sleep, 2,_SC(".i")),
  546. #ifdef WITH_UUID
  547. _DECL_FUNC(getuuid, 0, NULL),
  548. #endif
  549. #ifndef _WIN32_WCE
  550. _DECL_FUNC(getmillicount,1,_SC(".")),
  551. _DECL_FUNC(getmillispan,2,_SC(".i")),
  552. #endif
  553. #ifdef USE_SIGNAL_HANDLER
  554. _DECL_FUNC(set_signal_received,2,_SC(".i")),
  555. _DECL_FUNC(get_signal_received,1,_SC(".")),
  556. _DECL_FUNC(signal,2,_SC(". i|s")),
  557. _DECL_FUNC(raise,2,_SC(". i|s")),
  558. _DECL_FUNC(signal_str2int,2,_SC(".s")),
  559. _DECL_FUNC(signal_int2str,2,_SC(".i")),
  560. #endif
  561. {0,0}
  562. };
  563. #undef _DECL_FUNC
  564. SQInteger sqstd_register_systemlib(HSQUIRRELVM v)
  565. {
  566. sq_pushstring(v,_SC("os"),-1);
  567. sq_newtable(v);
  568. SQInteger i=0;
  569. while(systemlib_funcs[i].name!=0)
  570. {
  571. sq_pushstring(v,systemlib_funcs[i].name,-1);
  572. sq_newclosure(v,systemlib_funcs[i].f,0);
  573. sq_setparamscheck(v,systemlib_funcs[i].nparamscheck,systemlib_funcs[i].typemask);
  574. sq_setnativeclosurename(v,-1,systemlib_funcs[i].name);
  575. sq_newslot(v,-3,SQFalse);
  576. i++;
  577. }
  578. sq_newslot(v,-3,SQTrue); //insert os
  579. return 1;
  580. }