lua.d 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. // quantumde1 developed software, licensed under BSD-0-Clause license.
  2. module scripts.lua;
  3. import bindbc.lua;
  4. import raylib;
  5. import variables;
  6. import graphics.effects;
  7. import std.conv;
  8. import system.abstraction;
  9. import system.config;
  10. import std.string;
  11. import graphics.engine;
  12. import graphics.playback;
  13. import std.file;
  14. import std.array;
  15. import std.algorithm;
  16. /*
  17. * This module provides Lua bindings for various engine functionalities.
  18. * Functions are built on top of engine built-in functions for execution from scripts.
  19. * Not all engine functions usable for scripting are yet implemented.
  20. */
  21. string hint;
  22. extern (C) nothrow int luaL_showHint(lua_State* L)
  23. {
  24. hint = "" ~ to!string(luaL_checkstring(L, 1));
  25. hintNeeded = true;
  26. return 0;
  27. }
  28. /* text window */
  29. extern (C) nothrow int luaL_dialogBox(lua_State* L)
  30. {
  31. showDialog = true;
  32. // parse table with text pages
  33. luaL_checktype(L, 1, LUA_TTABLE);
  34. int textTableLength = cast(int) lua_objlen(L, 1);
  35. messageGlobal = new string[](textTableLength);
  36. for (int i = 0; i < textTableLength; i++) {
  37. lua_rawgeti(L, 1, i + 1);
  38. messageGlobal[i] = luaL_checkstring(L, -1).to!string;
  39. backlogText ~= messageGlobal[i];
  40. lua_pop(L, 1);
  41. }
  42. //parse table with choices
  43. luaL_checktype(L, 2, LUA_TTABLE);
  44. int choicesLength = cast(int) lua_objlen(L, 2);
  45. choices = new string[choicesLength];
  46. for (int i = 0; i < choicesLength; i++)
  47. {
  48. lua_rawgeti(L, 2, i + 1);
  49. choices[i] = luaL_checkstring(L, -1).to!string;
  50. lua_pop(L, 1);
  51. }
  52. //if provided, get page on which choices must be shown
  53. if (lua_gettop(L) == 3) {
  54. choicePage = cast(int)luaL_checkinteger(L, 3);
  55. }
  56. //if provided, change speed of showing text
  57. if (lua_gettop(L) == 4) {
  58. typingSpeed = cast(float) luaL_checknumber(L, 7);
  59. }
  60. return 0;
  61. }
  62. extern (C) nothrow int luaL_getAnswerValue(lua_State* L)
  63. {
  64. lua_pushinteger(L, selectedChoice);
  65. return 1;
  66. }
  67. extern (C) nothrow int luaL_isDialogExecuted(lua_State *L) {
  68. lua_pushboolean(L, showDialog);
  69. return 1;
  70. }
  71. extern (C) nothrow int luaL_dialogAnswerValue(lua_State* L)
  72. {
  73. lua_pushinteger(L, selectedChoice);
  74. return 1;
  75. }
  76. /* background drawing and loading */
  77. extern (C) nothrow int luaL_load2Dbackground(lua_State* L)
  78. {
  79. try
  80. {
  81. int index = cast(int) luaL_checkinteger(L, 2);
  82. //if index too big, extending array
  83. if (index >= backgrounds.length) {
  84. backgrounds.length = index + 1;
  85. }
  86. // if texture with same Index already loaded, unloading it
  87. if (index < backgrounds.length && backgrounds[index].id != 0) {
  88. UnloadTexture(backgrounds[index]);
  89. }
  90. backgrounds[index] = LoadTexture(luaL_checkstring(L, 1));
  91. }
  92. catch (Exception e)
  93. {
  94. debugWriteln(e.msg);
  95. }
  96. return 0;
  97. }
  98. extern (C) nothrow int luaL_draw2Dbackground(lua_State* L)
  99. {
  100. try
  101. {
  102. backgroundTexture = backgrounds[luaL_checkinteger(L, 1)];
  103. neededDraw2D = true;
  104. }
  105. catch (Exception e)
  106. {
  107. debugWriteln(e.msg);
  108. }
  109. return 0;
  110. }
  111. extern (C) nothrow int luaL_stopDraw2Dbackground(lua_State* L)
  112. {
  113. try
  114. {
  115. backgroundTexture = Texture2D();
  116. neededDraw2D = true;
  117. }
  118. catch (Exception e)
  119. {
  120. debugWriteln(e.msg);
  121. }
  122. return 0;
  123. }
  124. extern (C) nothrow int luaL_unload2Dbackground(lua_State* L)
  125. {
  126. UnloadTexture(backgrounds[cast(int) luaL_checkinteger(L, 1)]);
  127. return 0;
  128. }
  129. /* character textures */
  130. extern (C) nothrow int luaL_load2Dcharacter(lua_State *L) {
  131. try
  132. {
  133. int count = cast(int) luaL_checkinteger(L, 2);
  134. if (count >= characterTextures.length) {
  135. characterTextures.length = count + 1;
  136. }
  137. characterTextures[count].texture = LoadTexture(luaL_checkstring(L, 1));
  138. characterTextures[count].width = characterTextures[count].texture.width;
  139. characterTextures[count].height = characterTextures[count].texture.height;
  140. characterTextures[count].drawTexture = false;
  141. }
  142. catch (Exception e) {
  143. debugWriteln(e.msg);
  144. }
  145. return 0;
  146. }
  147. extern (C) nothrow int luaL_draw2Dcharacter(lua_State* L)
  148. {
  149. try {
  150. //configuring needed parameters in characterTextures like coordinates, scale and drawTexture(its a boolean value which checks need this texture to be drawn or not)
  151. int count = to!int(luaL_checkinteger(L, 4));
  152. characterTextures[count].scale = luaL_checknumber(L, 3);
  153. characterTextures[count].y = cast(int) luaL_checkinteger(L, 2);
  154. characterTextures[count].x = cast(int) luaL_checkinteger(L, 1);
  155. characterTextures[count].drawTexture = true;
  156. debugWriteln("Count: ", count, " drawTexture cond: ", characterTextures[count].drawTexture);
  157. } catch (Exception e) {
  158. debugWriteln(e.msg);
  159. }
  160. return 0;
  161. }
  162. extern (C) nothrow int luaL_stopDraw2Dcharacter(lua_State* L)
  163. {
  164. int count = cast(int) luaL_checkinteger(L, 1);
  165. characterTextures[count].drawTexture = false;
  166. return 0;
  167. }
  168. extern (C) nothrow int luaL_unload2Dcharacter(lua_State *L) {
  169. int count = cast(int) luaL_checkinteger(L, 1);
  170. UnloadTexture(characterTextures[count].texture);
  171. return 0;
  172. }
  173. /* music and video */
  174. extern (C) nothrow int luaL_loadMusic(lua_State* L)
  175. {
  176. try
  177. {
  178. musicPath = cast(char*) luaL_checkstring(L, 1);
  179. music = LoadMusicStream(musicPath);
  180. }
  181. catch (Exception e)
  182. {
  183. debugWriteln(e.msg);
  184. }
  185. return 0;
  186. }
  187. extern (C) nothrow int luaL_playMusic(lua_State* L)
  188. {
  189. PlayMusicStream(music);
  190. return 0;
  191. }
  192. extern (C) nothrow int luaL_stopMusic(lua_State* L)
  193. {
  194. StopMusicStream(music);
  195. return 0;
  196. }
  197. extern (C) nothrow int luaL_unloadMusic(lua_State* L)
  198. {
  199. UnloadMusicStream(music);
  200. return 0;
  201. }
  202. extern (C) nothrow int luaL_playSfx(lua_State *L) {
  203. try {
  204. playSfx(to!string(luaL_checkstring(L, 1)));
  205. } catch (Exception e) {
  206. debugWriteln(e.msg);
  207. }
  208. return 0;
  209. }
  210. extern (C) nothrow int luaL_stopSfx(lua_State *L) {
  211. StopSound(sfx);
  212. return 0;
  213. }
  214. extern (C) nothrow int luaL_playVideo(lua_State* L)
  215. {
  216. try
  217. {
  218. videoFinished = false;
  219. playVideo(luaL_checkstring(L, 1).to!string);
  220. }
  221. catch (Exception e)
  222. {
  223. debugWriteln(e.msg);
  224. }
  225. return 0;
  226. }
  227. /* ui animations */
  228. extern (C) nothrow int luaL_moveCamera(lua_State *L) {
  229. try {
  230. float targetX = cast(float) luaL_checknumber(L, 1);
  231. float targetY = cast(float) luaL_checknumber(L, 2);
  232. float zoom = cast(float) luaL_optnumber(L, 3, 1.0f);
  233. float speed = cast(float) luaL_optnumber(L, 4, 5.0f);
  234. cameraTargetX = targetX;
  235. cameraTargetY = targetY;
  236. cameraTargetZoom = zoom;
  237. cameraMoveSpeed = speed;
  238. isCameraMoving = true;
  239. } catch (Exception e) {
  240. debugWriteln(e.msg);
  241. }
  242. return 0;
  243. }
  244. extern (C) nothrow int luaL_isCameraMoving(lua_State *L) {
  245. lua_pushboolean(L, isCameraMoving);
  246. return 1;
  247. }
  248. extern (C) nothrow int luaL_loadUIAnimation(lua_State *L) {
  249. try {
  250. //loads from uifx folder HPFF files, in which png textures are stored
  251. framesUI = loadAnimationFramesUI(to!string(luaL_checkstring(L, 1)), to!string(luaL_checkstring(L, 2)));
  252. if (lua_gettop(L) == 3) {
  253. frameDuration = luaL_checknumber(L, 3);
  254. debug debugWriteln("frameDuration: ", frameDuration);
  255. }
  256. } catch (Exception e) {
  257. debugWriteln(e.msg);
  258. }
  259. return 0;
  260. }
  261. extern (C) nothrow int luaL_playUIAnimation(lua_State *L) {
  262. debug debugWriteln("Animation UI start");
  263. try {
  264. playAnimation = true;
  265. } catch (Exception e) {
  266. debugWriteln(e.msg);
  267. }
  268. return 0;
  269. }
  270. extern (C) nothrow int luaL_stopUIAnimation(lua_State *L) {
  271. playAnimation = false;
  272. debug debugWriteln("Animation UI stop");
  273. frameDuration = 0.016f;
  274. currentFrame = 0;
  275. return 0;
  276. }
  277. extern (C) nothrow int luaL_unloadUIAnimation(lua_State *L) {
  278. try {
  279. for (int i = 0; i < framesUI.length; i++) {
  280. UnloadTexture(framesUI[i]);
  281. }
  282. } catch (Exception e) {
  283. debugWriteln(e.msg);
  284. }
  285. return 0;
  286. }
  287. /* system */
  288. extern (C) nothrow int luaL_getScreenWidth(lua_State* L)
  289. {
  290. lua_pushinteger(L, GetScreenWidth());
  291. return 1;
  292. }
  293. extern (C) nothrow int luaL_getScreenHeight(lua_State* L)
  294. {
  295. lua_pushinteger(L, GetScreenHeight());
  296. return 1;
  297. }
  298. extern (C) nothrow int luaL_getUsedLanguage(lua_State* L)
  299. {
  300. lua_pushstring(L, usedLang.toStringz());
  301. return 1;
  302. }
  303. extern (C) nothrow int luaL_2dModeEnable(lua_State* L)
  304. {
  305. neededDraw2D = true;
  306. return 0;
  307. }
  308. extern (C) nothrow int luaL_2dModeDisable(lua_State* L)
  309. {
  310. neededDraw2D = false;
  311. return 0;
  312. }
  313. extern (C) nothrow int luaL_setGameFont(lua_State* L)
  314. {
  315. const char* x = luaL_checkstring(L, 1);
  316. debugWriteln("Setting custom font: ", x.to!string);
  317. int[512] codepoints = 0;
  318. //configuring both cyrillic and latin fonts if available
  319. foreach (i; 0 .. 95)
  320. {
  321. codepoints[i] = 32 + i;
  322. }
  323. foreach (i; 0 .. 255)
  324. {
  325. codepoints[96 + i] = 0x400 + i;
  326. }
  327. textFont = LoadFontEx(x, 40, codepoints.ptr, codepoints.length);
  328. return 0;
  329. }
  330. extern (C) nothrow int luaL_getTime(lua_State* L)
  331. {
  332. //getTime() returns current time.
  333. lua_pushnumber(L, GetTime());
  334. return 1;
  335. }
  336. extern (C) nothrow int luaL_isKeyPressed(lua_State* L)
  337. {
  338. try
  339. {
  340. int keyCode = cast(int)luaL_checkinteger(L, 1);
  341. lua_pushboolean(L, IsKeyPressed(keyCode).to!bool);
  342. return 1;
  343. }
  344. catch (Exception e)
  345. {
  346. debugWriteln(e.msg);
  347. return 1;
  348. }
  349. }
  350. extern (C) nothrow int luaL_loadScript(lua_State* L)
  351. {
  352. for (int i = cast(int)characterTextures.length; i < characterTextures.length; i++)
  353. {
  354. UnloadTexture(characterTextures[i].texture);
  355. }
  356. for (int i = cast(int)backgrounds.length; i < backgrounds.length; i++)
  357. {
  358. UnloadTexture(backgrounds[i]);
  359. }
  360. try
  361. {
  362. luaExec = luaL_checkstring(L, 1).to!string;
  363. resetAllScriptValues();
  364. }
  365. catch (Exception e)
  366. {
  367. debugWriteln(e.msg);
  368. }
  369. luaReload = true;
  370. return 0;
  371. }
  372. extern (C) nothrow int luaL_setGameState(lua_State *L) {
  373. currentGameState = cast(int)luaL_checkinteger(L, 1);
  374. return 0;
  375. }
  376. /* raylib direct bindings for graphics */
  377. /* basic */
  378. extern (C) nothrow int luaL_loadTexture(lua_State *L) {
  379. const char* fileName = luaL_checkstring(L, 1);
  380. Texture2D texture = LoadTexture(fileName);
  381. Texture2D* texturePtr = cast(Texture2D*)lua_newuserdata(L, Texture2D.sizeof);
  382. *texturePtr = texture;
  383. if (luaL_newmetatable(L, "Texture")) {
  384. lua_pushcfunction(L, &luaL_textureGC);
  385. lua_setfield(L, -2, "__gc");
  386. }
  387. lua_setmetatable(L, -2);
  388. return 1;
  389. }
  390. extern (C) nothrow int luaL_textureGC(lua_State *L) {
  391. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  392. UnloadTexture(*texture);
  393. return 0;
  394. }
  395. extern (C) nothrow int luaL_drawTexture(lua_State *L) {
  396. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  397. int x = cast(int)luaL_checkinteger(L, 2);
  398. int y = cast(int)luaL_checkinteger(L, 3);
  399. Color color = Colors.WHITE;
  400. if (lua_gettop(L) >= 4 && lua_istable(L, 4)) {
  401. lua_getfield(L, 4, "r");
  402. color.r = cast(ubyte)lua_tointeger(L, -1);
  403. lua_pop(L, 1);
  404. lua_getfield(L, 4, "g");
  405. color.g = cast(ubyte)lua_tointeger(L, -1);
  406. lua_pop(L, 1);
  407. lua_getfield(L, 4, "b");
  408. color.b = cast(ubyte)lua_tointeger(L, -1);
  409. lua_pop(L, 1);
  410. lua_getfield(L, 4, "a");
  411. color.a = cast(ubyte)lua_tointeger(L, -1);
  412. lua_pop(L, 1);
  413. }
  414. DrawTexture(*texture, x, y, color);
  415. return 0;
  416. }
  417. extern (C) nothrow int luaL_getTextureWidth(lua_State *L) {
  418. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  419. lua_pushinteger(L, texture.width);
  420. return 1;
  421. }
  422. extern (C) nothrow int luaL_getTextureHeight(lua_State *L) {
  423. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  424. lua_pushinteger(L, texture.height);
  425. return 1;
  426. }
  427. extern (C) nothrow int luaL_drawText(lua_State *L) {
  428. const char* text = luaL_checkstring(L, 1);
  429. int x = cast(int)luaL_checkinteger(L, 2);
  430. int y = cast(int)luaL_checkinteger(L, 3);
  431. int fontSize = cast(int)luaL_optinteger(L, 4, 20);
  432. Color color = Colors.WHITE;
  433. if (lua_istable(L, 5)) {
  434. lua_getfield(L, 5, "r");
  435. color.r = cast(ubyte)lua_tointeger(L, -1);
  436. lua_pop(L, 1);
  437. lua_getfield(L, 5, "g");
  438. color.g = cast(ubyte)lua_tointeger(L, -1);
  439. lua_pop(L, 1);
  440. lua_getfield(L, 5, "b");
  441. color.b = cast(ubyte)lua_tointeger(L, -1);
  442. lua_pop(L, 1);
  443. lua_getfield(L, 5, "a");
  444. color.a = cast(ubyte)lua_tointeger(L, -1);
  445. lua_pop(L, 1);
  446. }
  447. DrawTextEx(textFont, text, Vector2(x, y), fontSize, 1.0f, color);
  448. return 0;
  449. }
  450. extern (C) nothrow int luaL_measureTextX(lua_State *L) {
  451. lua_pushinteger(L, cast(int)MeasureTextEx(textFont, luaL_checkstring(L, 1), cast(int)luaL_checkinteger(L, 2), 1.0f).x);
  452. return 1;
  453. }
  454. extern (C) nothrow int luaL_measureTextY(lua_State *L) {
  455. lua_pushinteger(L, cast(int)MeasureTextEx(textFont, luaL_checkstring(L, 1), cast(int)luaL_checkinteger(L, 2), 1.0f).y);
  456. return 1;
  457. }
  458. /* extended */
  459. extern (C) nothrow int luaL_drawTextureEx(lua_State *L) {
  460. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  461. float x = luaL_checknumber(L, 2);
  462. float y = luaL_checknumber(L, 3);
  463. float rotation = luaL_optnumber(L, 4, 0);
  464. float scale = luaL_optnumber(L, 5, 1);
  465. Color color = Colors.WHITE;
  466. if (lua_istable(L, 6)) {
  467. lua_getfield(L, 6, "r");
  468. color.r = cast(ubyte)lua_tointeger(L, -1);
  469. lua_pop(L, 1);
  470. lua_getfield(L, 6, "g");
  471. color.g = cast(ubyte)lua_tointeger(L, -1);
  472. lua_pop(L, 1);
  473. lua_getfield(L, 6, "b");
  474. color.b = cast(ubyte)lua_tointeger(L, -1);
  475. lua_pop(L, 1);
  476. lua_getfield(L, 6, "a");
  477. color.a = cast(ubyte)lua_tointeger(L, -1);
  478. lua_pop(L, 1);
  479. }
  480. DrawTextureEx(*texture, Vector2(x, y), rotation, scale, color);
  481. return 0;
  482. }
  483. /* Register functions */
  484. extern (C) nothrow void luaL_loader(lua_State* L)
  485. {
  486. lua_register(L, "dialogBox", &luaL_dialogBox);
  487. lua_register(L, "dialogAnswerValue", &luaL_dialogAnswerValue);
  488. lua_register(L, "isDialogExecuted", &luaL_isDialogExecuted);
  489. lua_register(L, "getAnswerValue", &luaL_getAnswerValue);
  490. lua_register(L, "loadAnimationUI", &luaL_loadUIAnimation);
  491. lua_register(L, "playAnimationUI", &luaL_playUIAnimation);
  492. lua_register(L, "stopAnimationUI", &luaL_stopUIAnimation);
  493. lua_register(L, "unloadAnimationUI", &luaL_unloadUIAnimation);
  494. lua_register(L, "moveCamera", &luaL_moveCamera);
  495. lua_register(L, "isCameraMoving", &luaL_isCameraMoving);
  496. lua_register(L, "playVideo", &luaL_playVideo);
  497. lua_register(L, "loadMusic", &luaL_loadMusic);
  498. lua_register(L, "playMusic", &luaL_playMusic);
  499. lua_register(L, "stopMusic", &luaL_stopMusic);
  500. lua_register(L, "unloadMusic", &luaL_unloadMusic);
  501. lua_register(L, "playSfx", &luaL_playSfx);
  502. lua_register(L, "stopSfx", &luaL_stopSfx);
  503. lua_register(L, "Begin2D", &luaL_2dModeEnable);
  504. lua_register(L, "End2D", &luaL_2dModeDisable);
  505. lua_register(L, "loadCharacter", &luaL_load2Dcharacter);
  506. lua_register(L, "drawCharacter", &luaL_draw2Dcharacter);
  507. lua_register(L, "stopDrawCharacter", &luaL_stopDraw2Dcharacter);
  508. lua_register(L, "unloadCharacter", &luaL_unload2Dcharacter);
  509. lua_register(L, "loadBackground", &luaL_load2Dbackground);
  510. lua_register(L, "drawBackground", &luaL_draw2Dbackground);
  511. lua_register(L, "stopDrawBackground", &luaL_stopDraw2Dbackground);
  512. lua_register(L, "unloadBackground", &luaL_unload2Dbackground);
  513. lua_register(L, "getTime", &luaL_getTime);
  514. lua_register(L, "loadScript", &luaL_loadScript);
  515. lua_register(L, "setFont", &luaL_setGameFont);
  516. lua_register(L, "getScreenHeight", &luaL_getScreenHeight);
  517. lua_register(L, "getScreenWidth", &luaL_getScreenWidth);
  518. lua_register(L, "isKeyPressed", &luaL_isKeyPressed);
  519. lua_register(L, "getLanguage", &luaL_getUsedLanguage);
  520. lua_register(L, "setGameState", &luaL_setGameState);
  521. //raylib direct bindings
  522. lua_register(L, "loadTexture", &luaL_loadTexture);
  523. lua_register(L, "drawTexture", &luaL_drawTexture);
  524. lua_register(L, "drawTextureEx", &luaL_drawTextureEx);
  525. lua_register(L, "drawText", &luaL_drawText);
  526. lua_register(L, "measureTextX", &luaL_measureTextX);
  527. lua_register(L, "measureTextY", &luaL_measureTextY);
  528. lua_register(L, "getTextureWidth", &luaL_getTextureWidth);
  529. lua_register(L, "getTextureHeight", &luaL_getTextureHeight);
  530. }
  531. int luaInit(string luaExec)
  532. {
  533. debugWriteln("loading Lua");
  534. L = luaL_newstate();
  535. luaL_openlibs(L);
  536. luaL_loader(L);
  537. debugWriteln("Executing next Lua file: ", luaExec);
  538. if (std.file.exists(luaExec) == false) {
  539. debugWriteln("Script file not found! Exiting.");
  540. return EngineExitCodes.EXIT_FILE_NOT_FOUND;
  541. }
  542. if (luaL_dofile(L, toStringz(luaExec)) != LUA_OK) {
  543. debugWriteln("Lua error: ", to!string(lua_tostring(L, -1)));
  544. return EngineExitCodes.EXIT_SCRIPT_ERROR;
  545. }
  546. return EngineExitCodes.EXIT_OK;
  547. }
  548. void luaEventLoop()
  549. {
  550. lua_getglobal(L, "EventLoop");
  551. if (lua_pcall(L, 0, 0, 0) != LUA_OK)
  552. {
  553. debug debugWriteln("Error in EventLoop: ", to!string(lua_tostring(L, -1)));
  554. }
  555. lua_pop(L, 0);
  556. }