lib_glue.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. #include <squirrel.h>
  2. #include <sqstdblob.h>
  3. #include "n2DLib/n2DLib.h"
  4. SQInteger register_global_func(HSQUIRRELVM v,SQFUNCTION f,const char *fname)
  5. {
  6. sq_pushroottable(v);
  7. sq_pushstring(v,fname,-1);
  8. sq_newclosure(v,f,0); //create a new function
  9. sq_newslot(v,-3, SQFalse);
  10. sq_pop(v,1); //pops the root table
  11. return 0;
  12. }
  13. SQRESULT register_lib(HSQUIRRELVM v, const SQChar *lib_name, const SQRegFunction *reg)
  14. {
  15. SQInteger top = sq_gettop(v);
  16. sq_pushstring(v,lib_name,-1);
  17. sq_newtable(v);
  18. int i = 0;
  19. while(reg[i].name != NULL) {
  20. const SQRegFunction* fun = &reg[i];
  21. sq_pushstring(v, fun->name, -1);
  22. sq_newclosure(v, fun->f, 0);
  23. sq_setparamscheck(v, fun->nparamscheck, fun->typemask);
  24. sq_setnativeclosurename(v, -1, fun->name);
  25. sq_newslot(v, -3, SQFalse);
  26. i++;
  27. }
  28. sq_newslot(v, -3, SQFalse);
  29. sq_settop(v,top);
  30. return SQ_ERROR;
  31. }
  32. //////////////////
  33. // n2DLib glue. //
  34. //////////////////
  35. // Key glue data
  36. #define GLUE_KEY(x) &KEY_NSPIRE_ ## x,
  37. #define GLUE_NUMBER_KEY(x) &KEY_NSPIRE_ ## x,
  38. static const t_key const * key_array[] = {
  39. #include "n2dlib_keys.xmacro"
  40. };
  41. #undef GLUE_KEY
  42. #undef GLUE_NUMBER_KEY
  43. #define GLUE_KEY(x) #x ,
  44. #define GLUE_NUMBER_KEY(x) "K_"#x ,
  45. static const char * key_array_names[] = {
  46. #include "n2dlib_keys.xmacro"
  47. };
  48. #undef GLUE_KEY
  49. #undef GLUE_NUMBER_KEY
  50. // Utilities
  51. SQInteger n2d_itofix (HSQUIRRELVM v)
  52. {
  53. int i;
  54. sq_getinteger(v, 2, &i);
  55. sq_pushinteger(v, itofix(i));
  56. return 1;
  57. }
  58. SQInteger n2d_fixtoi (HSQUIRRELVM v)
  59. {
  60. Fixed f;
  61. sq_getinteger(v, 2, &f);
  62. sq_pushinteger(v, fixtoi(f));
  63. return 1;
  64. }
  65. SQInteger n2d_fixdiv (HSQUIRRELVM v)
  66. {
  67. Fixed x, y;
  68. sq_getinteger(v, 2, &x);
  69. sq_getinteger(v, 3, &y);
  70. sq_pushinteger(v, fixdiv(x, y));
  71. }
  72. SQInteger n2d_fixmul (HSQUIRRELVM v)
  73. {
  74. Fixed x, y;
  75. sq_getinteger(v, 2, &x);
  76. sq_getinteger(v, 3, &y);
  77. sq_pushinteger(v, fixmul(x, y));
  78. return 1;
  79. }
  80. SQInteger n2d_fixcos (HSQUIRRELVM v)
  81. {
  82. Fixed angle;
  83. sq_getinteger(v, 2, &angle);
  84. sq_pushinteger(v, fixcos(angle));
  85. return 1;
  86. }
  87. SQInteger n2d_fixsin (HSQUIRRELVM v)
  88. {
  89. Fixed angle;
  90. sq_getinteger(v, 2, &angle);
  91. sq_pushinteger(v, fixsin(angle));
  92. return 1;
  93. }
  94. // Drawing routines
  95. SQInteger n2d_initBuffering (HSQUIRRELVM v)
  96. {
  97. initBuffering();
  98. return 0;
  99. }
  100. SQInteger n2d_updateScreen (HSQUIRRELVM v)
  101. {
  102. updateScreen();
  103. return 0;
  104. }
  105. SQInteger n2d_deinitBuffering (HSQUIRRELVM v)
  106. {
  107. deinitBuffering();
  108. return 0;
  109. }
  110. SQInteger n2d_clearBuffer (HSQUIRRELVM v)
  111. {
  112. unsigned int color;
  113. sq_getinteger(v, 2, &color);
  114. clearBuffer((unsigned short) color);
  115. return 0;
  116. }
  117. SQInteger n2d_clearBufferB (HSQUIRRELVM v)
  118. {
  119. clearBufferB();
  120. return 0;
  121. }
  122. SQInteger n2d_clearBufferW (HSQUIRRELVM v)
  123. {
  124. clearBufferW();
  125. return 0;
  126. }
  127. SQInteger n2d_getPixel (HSQUIRRELVM v)
  128. {
  129. SQUserPointer image;
  130. unsigned int x, y;
  131. sqstd_getblob(v, 2, &image);
  132. sq_getinteger(v, 3, &x);
  133. sq_getinteger(v, 4, &y);
  134. unsigned int value = getPixel((unsigned short*) image, x, y);
  135. sq_pushinteger(v, value);
  136. return 1;
  137. }
  138. SQInteger n2d_setPixelUnsafe (HSQUIRRELVM v)
  139. {
  140. unsigned int x, y, color;
  141. sq_getinteger(v, 2, &x);
  142. sq_getinteger(v, 3, &y);
  143. sq_getinteger(v, 4, &color);
  144. setPixelUnsafe(x, y, (unsigned short)color);
  145. return 0;
  146. }
  147. SQInteger n2d_setPixel (HSQUIRRELVM v)
  148. {
  149. unsigned int x, y, color;
  150. sq_getinteger(v, 2, &x);
  151. sq_getinteger(v, 3, &y);
  152. sq_getinteger(v, 4, &color);
  153. setPixel(x, y, (unsigned short)color);
  154. return 0;
  155. }
  156. SQInteger n2d_setPixelRGB (HSQUIRRELVM v)
  157. {
  158. unsigned int x, y, r, g, b;
  159. sq_getinteger(v, 2, &x);
  160. sq_getinteger(v, 3, &y);
  161. sq_getinteger(v, 4, &r);
  162. sq_getinteger(v, 5, &g);
  163. sq_getinteger(v, 6, &b);
  164. setPixelRGB(x, y, (unsigned char)r, (unsigned char)g, (unsigned char)b);
  165. return 0;
  166. }
  167. SQInteger n2d_drawHLine (HSQUIRRELVM v)
  168. {
  169. int y, x1, x2;
  170. unsigned int color;
  171. sq_getinteger(v, 2, &y);
  172. sq_getinteger(v, 3, &x1);
  173. sq_getinteger(v, 4, &x2);
  174. sq_getinteger(v, 5, &color);
  175. drawHLine(y, x1, x2, color);
  176. return 0;
  177. }
  178. SQInteger n2d_drawVLine (HSQUIRRELVM v)
  179. {
  180. int x, y1, y2;
  181. unsigned int color;
  182. sq_getinteger(v, 2, &x);
  183. sq_getinteger(v, 3, &y1);
  184. sq_getinteger(v, 4, &y2);
  185. sq_getinteger(v, 5, &color);
  186. drawVLine(x, y1, y2, color);
  187. return 0;
  188. }
  189. SQInteger n2d_fillRect (HSQUIRRELVM v)
  190. {
  191. int x, y, w, h, color;
  192. sq_getinteger(v, 2, &x);
  193. sq_getinteger(v, 3, &y);
  194. sq_getinteger(v, 4, &w);
  195. sq_getinteger(v, 5, &h);
  196. sq_getinteger(v, 6, &color);
  197. fillRect(x, y, w, h, color);
  198. }
  199. SQInteger n2d_drawSprite (HSQUIRRELVM v)
  200. {
  201. SQUserPointer image;
  202. unsigned x, y, flash;
  203. unsigned int flash_color;
  204. sqstd_getblob(v, 2, &image);
  205. sq_getinteger(v, 3, &x);
  206. sq_getinteger(v, 4, &y);
  207. sq_getinteger(v, 5, &flash);
  208. sq_getinteger(v, 6, &flash_color);
  209. drawSprite((const unsigned short*)image, x, y, flash, (unsigned short) flash_color);
  210. return 0;
  211. }
  212. SQInteger n2d_drawSpritePart (HSQUIRRELVM v)
  213. {
  214. SQUserPointer image;
  215. unsigned x, y, flash;
  216. unsigned xp, yp, wp, hp;
  217. unsigned int flash_color;
  218. sqstd_getblob(v, 2, &image);
  219. sq_getinteger(v, 3, &x);
  220. sq_getinteger(v, 4, &y);
  221. sq_getinteger(v, 5, &xp);
  222. sq_getinteger(v, 6, &yp);
  223. sq_getinteger(v, 7, &wp);
  224. sq_getinteger(v, 8, &hp);
  225. sq_getinteger(v, 9, &flash);
  226. sq_getinteger(v, 10, &flash_color);
  227. Rect r = {xp, yp, wp, hp};
  228. drawSpritePart((const unsigned short*)image, x, y, &r, flash, (unsigned short) flash_color);
  229. return 0;
  230. }
  231. SQInteger n2d_drawSpriteScaled (HSQUIRRELVM v)
  232. {
  233. SQUserPointer image;
  234. int xs, ys, ws, hs, flash;
  235. unsigned int flash_color;
  236. sqstd_getblob(v, 2, &image);
  237. sq_getinteger(v, 3, &xs);
  238. sq_getinteger(v, 4, &ys);
  239. sq_getinteger(v, 5, &hs);
  240. sq_getinteger(v, 6, &ws);
  241. sq_getinteger(v, 7, &flash);
  242. sq_getinteger(v, 8, &flash_color);
  243. Rect r = {xs, ys, ws, hs};
  244. drawSpriteScaled((const unsigned short*)image, &r, flash, (unsigned short) flash_color);
  245. return 0;
  246. }
  247. SQInteger n2d_drawSpriteRotated (HSQUIRRELVM v)
  248. {
  249. SQUserPointer image;
  250. int xsr, ysr, wsr, hsr;
  251. int xrc, yrc, wrc, hrc;
  252. int angle, flash;
  253. unsigned int flash_color;
  254. sqstd_getblob(v, 2, &image);
  255. sq_getinteger(v, 3, &xsr);
  256. sq_getinteger(v, 4, &ysr);
  257. sq_getinteger(v, 5, &wsr);
  258. sq_getinteger(v, 6, &hsr);
  259. sq_getinteger(v, 7, &xrc);
  260. sq_getinteger(v, 8, &yrc);
  261. sq_getinteger(v, 9, &angle);
  262. sq_getinteger(v, 10, &flash);
  263. sq_getinteger(v, 11, &flash_color);
  264. Rect sr = {xsr, ysr, wsr, hsr};
  265. Rect rc = {xrc, yrc, 0, 0};
  266. drawSpriteRotated((const unsigned short*)image, &sr, &rc, (Fixed)angle, flash, flash_color);
  267. return 0;
  268. }
  269. SQInteger n2d_drawLine (HSQUIRRELVM v)
  270. {
  271. int x1, x2, y1, y2;
  272. unsigned int color;
  273. sq_getinteger(v, 2, &x1);
  274. sq_getinteger(v, 3, &y1);
  275. sq_getinteger(v, 4, &x2);
  276. sq_getinteger(v, 5, &y2);
  277. sq_getinteger(v, 6, &color);
  278. drawLine(x1, y1, x2, y2, color);
  279. return 0;
  280. }
  281. SQInteger n2d_fillCircle (HSQUIRRELVM v)
  282. {
  283. int x, y, r, color;
  284. sq_getinteger(v, 2, &x);
  285. sq_getinteger(v, 3, &y);
  286. sq_getinteger(v, 4, &r);
  287. sq_getinteger(v, 5, &color);
  288. fillCircle(x, y, r, color);
  289. return 0;
  290. }
  291. SQInteger n2d_fillEllipse (HSQUIRRELVM v)
  292. {
  293. int x, y, r, R, color;
  294. sq_getinteger(v, 2, &x);
  295. sq_getinteger(v, 3, &y);
  296. sq_getinteger(v, 4, &r);
  297. sq_getinteger(v, 5, &R);
  298. sq_getinteger(v, 6, &color);
  299. fillEllipse(x, y, r, R, color);
  300. return 0;
  301. }
  302. SQInteger n2d_drawString (HSQUIRRELVM v)
  303. {
  304. int x, y, margin;
  305. SQChar* str;
  306. unsigned int fc, olc;
  307. sq_getinteger(v, 2, &x);
  308. sq_getinteger(v, 3, &y);
  309. sq_getinteger(v, 4, &margin);
  310. sq_getstring(v, 5, (const SQChar**)&str);
  311. sq_getinteger(v, 6, &fc);
  312. sq_getinteger(v, 7, &olc);
  313. drawString(&x, &y, margin, (char*)str, fc, olc);
  314. // pushing new X/Y values.
  315. sq_newarray(v, 2);
  316. sq_pushinteger(v, x);
  317. sq_set(v, -2);
  318. sq_pushinteger(v, y);
  319. sq_set(v, -2);
  320. return 1;
  321. }
  322. SQInteger n2d_drawDecimal (HSQUIRRELVM v)
  323. {
  324. int x, y, n;
  325. unsigned int fc, olc;
  326. sq_getinteger(v, 2, &x);
  327. sq_getinteger(v, 3, &y);
  328. sq_getinteger(v, 4, &n);
  329. sq_getinteger(v, 5, &fc);
  330. sq_getinteger(v, 6, &olc);
  331. drawDecimal(&x, &y, n, (unsigned short)fc, (unsigned short)olc);
  332. // pushing new X/Y values.
  333. sq_newarray(v, 2);
  334. sq_pushinteger(v, x);
  335. sq_set(v, -2);
  336. sq_pushinteger(v, y);
  337. sq_set(v, -2);
  338. return 1;
  339. }
  340. SQInteger n2d_drawChar (HSQUIRRELVM v)
  341. {
  342. int x, y, margin, ch;
  343. unsigned int fc, olc;
  344. sq_getinteger(v, 2, &x);
  345. sq_getinteger(v, 3, &y);
  346. sq_getinteger(v, 4, &margin);
  347. sq_getinteger(v, 5, &ch);
  348. sq_getinteger(v, 6, &fc);
  349. sq_getinteger(v, 7, &olc);
  350. drawChar(&x, &y, margin, ch, fc, olc);
  351. // pushing new X/Y values.
  352. sq_newarray(v, 2);
  353. sq_pushinteger(v, x);
  354. sq_set(v, -2);
  355. sq_pushinteger(v, y);
  356. sq_set(v, -2);
  357. return 1;
  358. }
  359. SQInteger n2d_numberWidth (HSQUIRRELVM v)
  360. {
  361. int n;
  362. sq_getinteger(v, 2, &n);
  363. sq_pushinteger(v, numberWidth(n));
  364. return 1;
  365. }
  366. SQInteger n2d_stringWidth (HSQUIRRELVM v)
  367. {
  368. SQChar* str;
  369. sq_getstring(v, 2, (const SQChar**)&str);
  370. sq_pushinteger(v, stringWidth((const char*)str));
  371. return 1;
  372. }
  373. SQInteger n2d_getKeyPressed (HSQUIRRELVM v)
  374. {
  375. t_key collect;
  376. int result = get_key_pressed(&collect);
  377. if(result)
  378. {
  379. sq_newtable(v);
  380. sq_pushstring(v, "row", -1);
  381. sq_pushinteger(v, collect.row);
  382. sq_newslot(v, -3, SQFalse);
  383. sq_pushstring(v, "col", -1);
  384. sq_pushinteger(v, collect.col);
  385. sq_newslot(v, -3, SQFalse);
  386. sq_pushstring(v, "tpad_row", -1);
  387. sq_pushinteger(v, collect.tpad_row);
  388. sq_newslot(v, -3, SQFalse);
  389. sq_pushstring(v, "tpad_col", -1);
  390. sq_pushinteger(v, collect.tpad_col);
  391. sq_newslot(v, -3, SQFalse);
  392. sq_pushstring(v, "tpad_arrow", -1);
  393. sq_pushinteger(v, collect.tpad_arrow);
  394. sq_newslot(v, -3, SQFalse);
  395. }
  396. else
  397. {
  398. sq_newtable(v);
  399. sq_pushstring(v, "row", -1);
  400. sq_pushinteger(v, _KEY_DUMMY_ROW);
  401. sq_newslot(v, -3, SQFalse);
  402. sq_pushstring(v, "col", -1);
  403. sq_pushinteger(v, _KEY_DUMMY_COL);
  404. sq_newslot(v, -3, SQFalse);
  405. sq_pushstring(v, "tpad_row", -1);
  406. sq_pushinteger(v, _KEY_DUMMY_ROW);
  407. sq_newslot(v, -3, SQFalse);
  408. sq_pushstring(v, "tpad_col", -1);
  409. sq_pushinteger(v,_KEY_DUMMY_COL);
  410. sq_newslot(v, -3, SQFalse);
  411. sq_pushstring(v, "tpad_arrow", -1);
  412. sq_pushinteger(v, TPAD_ARROW_NONE);
  413. sq_newslot(v, -3, SQFalse);
  414. }
  415. return 1;
  416. }
  417. SQInteger n2d_isKey (HSQUIRRELVM v)
  418. {
  419. t_key collect;
  420. int arrow;
  421. int key_index;
  422. sq_getinteger(v, 3, &key_index);
  423. sq_pushstring(v, "row", -1);
  424. sq_get(v, 2);
  425. sq_getinteger(v, -1, &collect.row);
  426. sq_pushstring(v, "col", -1);
  427. sq_get(v, 2);
  428. sq_getinteger(v, -1, &collect.col);
  429. sq_pushstring(v, "tpad_row", -1);
  430. sq_get(v, 2);
  431. sq_getinteger(v, -1, &collect.tpad_row);
  432. sq_pushstring(v, "tpad_col", -1);
  433. sq_get(v, 2);
  434. sq_getinteger(v, -1, &collect.tpad_col);
  435. sq_pushstring(v, "tpad_arrow", -1);
  436. sq_get(v, 2);
  437. sq_getinteger(v, -1, &arrow);
  438. collect.tpad_arrow = arrow;
  439. if((key_index>=0) && (key_index < sizeof(key_array)/sizeof(t_key*)))
  440. {
  441. t_key* ref = key_array[key_index];
  442. sq_pushbool(v, isKey(collect, *ref));
  443. }
  444. else
  445. sq_pushbool(v, false);
  446. return 1;
  447. }
  448. SQInteger n2d_loadBMP (HSQUIRRELVM v)
  449. {
  450. SQChar *path;
  451. unsigned int transparency_color;
  452. sq_getstring(v, 2, (const SQChar**)&path);
  453. sq_getinteger(v, 3, &transparency_color);
  454. unsigned short *bmp = loadBMP((const char*)path, (unsigned short)transparency_color);
  455. if(bmp == NULL)
  456. {
  457. sq_pushnull(v);
  458. return 1;
  459. }
  460. int bmp_length = sizeof(unsigned short) * (bmp[0] * bmp[1] + 3);
  461. SQUserPointer blob = sqstd_createblob(v, bmp_length);
  462. memcpy(blob, bmp, bmp_length);
  463. free(bmp);
  464. return 1;
  465. }
  466. #define _DECL_GLOBALIO_FUNC(name,nparams,typecheck) {_SC(#name),n2d_##name,nparams,typecheck}
  467. static const SQRegFunction n2d_funcs[]={
  468. _DECL_GLOBALIO_FUNC(itofix,2,_SC(".i")),
  469. _DECL_GLOBALIO_FUNC(fixtoi,2,_SC(".i")),
  470. _DECL_GLOBALIO_FUNC(fixdiv,2,_SC(".ii")),
  471. _DECL_GLOBALIO_FUNC(fixmul,2,_SC(".ii")),
  472. _DECL_GLOBALIO_FUNC(fixsin,2,_SC(".i")),
  473. _DECL_GLOBALIO_FUNC(fixcos,2,_SC(".i")),
  474. _DECL_GLOBALIO_FUNC(initBuffering,1,_SC(".")),
  475. _DECL_GLOBALIO_FUNC(deinitBuffering,1,_SC(".")),
  476. _DECL_GLOBALIO_FUNC(updateScreen,1,_SC(".")),
  477. _DECL_GLOBALIO_FUNC(clearBuffer,2,_SC(".i")),
  478. _DECL_GLOBALIO_FUNC(clearBufferB,1,_SC(".")),
  479. _DECL_GLOBALIO_FUNC(clearBufferW,1,_SC(".")),
  480. _DECL_GLOBALIO_FUNC(getPixel,4,_SC(".sii")),
  481. _DECL_GLOBALIO_FUNC(setPixelUnsafe,4,_SC(".iii")),
  482. _DECL_GLOBALIO_FUNC(setPixel,4,_SC(".iii")),
  483. _DECL_GLOBALIO_FUNC(setPixelRGB,6,_SC(".iiiii")),
  484. _DECL_GLOBALIO_FUNC(drawHLine,5,_SC(".iiii")),
  485. _DECL_GLOBALIO_FUNC(drawVLine,5,_SC(".iiii")),
  486. _DECL_GLOBALIO_FUNC(fillRect,6,_SC(".iiiii")),
  487. _DECL_GLOBALIO_FUNC(drawSprite,6,_SC(".xiiii")),
  488. _DECL_GLOBALIO_FUNC(drawSpritePart,10,_SC(".xiiiiiiii")),
  489. _DECL_GLOBALIO_FUNC(drawSpriteScaled,8,_SC(".xiiiiiiii")),
  490. _DECL_GLOBALIO_FUNC(drawSpriteRotated,11,_SC(".xiiiiiiiii")),
  491. _DECL_GLOBALIO_FUNC(drawLine,6,_SC(".iiiii")),
  492. _DECL_GLOBALIO_FUNC(fillRect,6,_SC(".iiiii")),
  493. _DECL_GLOBALIO_FUNC(fillCircle,5,_SC(".iiii")),
  494. _DECL_GLOBALIO_FUNC(fillEllipse,5,_SC(".iiiii")),
  495. _DECL_GLOBALIO_FUNC(drawString,7,_SC(".iiisii")),
  496. _DECL_GLOBALIO_FUNC(drawDecimal,6,_SC(".iiiii")),
  497. _DECL_GLOBALIO_FUNC(drawChar,7,_SC(".iiiiiii")),
  498. _DECL_GLOBALIO_FUNC(numberWidth,2,_SC(".i")),
  499. _DECL_GLOBALIO_FUNC(stringWidth,2,_SC(".s")),
  500. _DECL_GLOBALIO_FUNC(getKeyPressed,1,_SC(".")),
  501. _DECL_GLOBALIO_FUNC(isKey,3,_SC(".ti")),
  502. _DECL_GLOBALIO_FUNC(loadBMP,3,_SC(".si")),
  503. {NULL,(SQFUNCTION)0,0,NULL}
  504. };
  505. SQRESULT register_keys (HSQUIRRELVM v)
  506. {
  507. SQInteger top = sq_gettop(v);
  508. SQObject enumeration_table;
  509. // Get const table
  510. sq_pushconsttable(v);
  511. // push new enum's name
  512. sq_pushstring(v,"n2dk",-1);
  513. // Create enum tale
  514. sq_newtable(v);
  515. // For each value, push it in the enum.
  516. for(int i = 0; i < sizeof(key_array)/sizeof(t_key*); i++)
  517. {
  518. // table.i = index;
  519. sq_pushstring(v, (SQChar*)key_array_names[i], -1);
  520. sq_pushinteger(v, i);
  521. sq_newslot(v, -3, false);
  522. }
  523. // Adding it to the const table
  524. sq_newslot(v, -3, SQFalse);
  525. // Popping the const table.
  526. sq_settop(v,top);
  527. }
  528. SQRESULT register_n2dlib (HSQUIRRELVM v)
  529. {
  530. register_keys(v);
  531. register_lib(v, _SC("n2d"), n2d_funcs);
  532. }
  533. #undef _DECL_GLOBALIO_FUNC