lua.d 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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_playSfx(lua_State *L) {
  198. try {
  199. playSfx(to!string(luaL_checkstring(L, 1)));
  200. } catch (Exception e) {
  201. debugWriteln(e.msg);
  202. }
  203. return 0;
  204. }
  205. extern (C) nothrow int luaL_stopSfx(lua_State *L) {
  206. StopSound(sfx);
  207. return 0;
  208. }
  209. extern (C) nothrow int luaL_playVideo(lua_State* L)
  210. {
  211. try
  212. {
  213. videoFinished = false;
  214. playVideo(luaL_checkstring(L, 1).to!string);
  215. }
  216. catch (Exception e)
  217. {
  218. debugWriteln(e.msg);
  219. }
  220. return 0;
  221. }
  222. /* ui animations */
  223. extern (C) nothrow int luaL_moveCamera(lua_State *L) {
  224. try {
  225. float targetX = cast(float) luaL_checknumber(L, 1);
  226. float targetY = cast(float) luaL_checknumber(L, 2);
  227. float zoom = cast(float) luaL_optnumber(L, 3, 1.0f);
  228. float speed = cast(float) luaL_optnumber(L, 4, 5.0f);
  229. cameraTargetX = targetX;
  230. cameraTargetY = targetY;
  231. cameraTargetZoom = zoom;
  232. cameraMoveSpeed = speed;
  233. isCameraMoving = true;
  234. } catch (Exception e) {
  235. debugWriteln(e.msg);
  236. }
  237. return 0;
  238. }
  239. extern (C) nothrow int luaL_isCameraMoving(lua_State *L) {
  240. lua_pushboolean(L, isCameraMoving);
  241. return 1;
  242. }
  243. extern (C) nothrow int luaL_loadUIAnimation(lua_State *L) {
  244. try {
  245. //loads from uifx folder HPFF files, in which png textures are stored
  246. framesUI = loadAnimationFramesUI(to!string(luaL_checkstring(L, 1)), to!string(luaL_checkstring(L, 2)));
  247. if (lua_gettop(L) == 3) {
  248. frameDuration = luaL_checknumber(L, 3);
  249. debug debugWriteln("frameDuration: ", frameDuration);
  250. }
  251. } catch (Exception e) {
  252. debugWriteln(e.msg);
  253. }
  254. return 0;
  255. }
  256. extern (C) nothrow int luaL_playUIAnimation(lua_State *L) {
  257. debug debugWriteln("Animation UI start");
  258. try {
  259. playAnimation = true;
  260. } catch (Exception e) {
  261. debugWriteln(e.msg);
  262. }
  263. return 0;
  264. }
  265. extern (C) nothrow int luaL_stopUIAnimation(lua_State *L) {
  266. playAnimation = false;
  267. debug debugWriteln("Animation UI stop");
  268. frameDuration = 0.016f;
  269. currentFrame = 0;
  270. return 0;
  271. }
  272. extern (C) nothrow int luaL_unloadUIAnimation(lua_State *L) {
  273. try {
  274. for (int i = 0; i < framesUI.length; i++) {
  275. UnloadTexture(framesUI[i]);
  276. }
  277. } catch (Exception e) {
  278. debugWriteln(e.msg);
  279. }
  280. return 0;
  281. }
  282. /* system */
  283. extern (C) nothrow int luaL_getScreenWidth(lua_State* L)
  284. {
  285. lua_pushinteger(L, GetScreenWidth());
  286. return 1;
  287. }
  288. extern (C) nothrow int luaL_getScreenHeight(lua_State* L)
  289. {
  290. lua_pushinteger(L, GetScreenHeight());
  291. return 1;
  292. }
  293. extern (C) nothrow int luaL_getUsedLanguage(lua_State* L)
  294. {
  295. lua_pushstring(L, usedLang.toStringz());
  296. return 1;
  297. }
  298. extern (C) nothrow int luaL_2dModeEnable(lua_State* L)
  299. {
  300. neededDraw2D = true;
  301. return 0;
  302. }
  303. extern (C) nothrow int luaL_2dModeDisable(lua_State* L)
  304. {
  305. neededDraw2D = false;
  306. return 0;
  307. }
  308. extern (C) nothrow int luaL_setGameFont(lua_State* L)
  309. {
  310. const char* x = luaL_checkstring(L, 1);
  311. debugWriteln("Setting custom font: ", x.to!string);
  312. int[512] codepoints = 0;
  313. //configuring both cyrillic and latin fonts if available
  314. foreach (i; 0 .. 95)
  315. {
  316. codepoints[i] = 32 + i;
  317. }
  318. foreach (i; 0 .. 255)
  319. {
  320. codepoints[96 + i] = 0x400 + i;
  321. }
  322. textFont = LoadFontEx(x, 40, codepoints.ptr, codepoints.length);
  323. return 0;
  324. }
  325. extern (C) nothrow int luaL_getTime(lua_State* L)
  326. {
  327. //getTime() returns current time.
  328. lua_pushnumber(L, GetTime());
  329. return 1;
  330. }
  331. extern (C) nothrow int luaL_isKeyPressed(lua_State* L)
  332. {
  333. try
  334. {
  335. int keyCode = cast(int)luaL_checkinteger(L, 1);
  336. lua_pushboolean(L, IsKeyPressed(keyCode).to!bool);
  337. return 1;
  338. }
  339. catch (Exception e)
  340. {
  341. debugWriteln(e.msg);
  342. return 1;
  343. }
  344. }
  345. extern (C) nothrow int luaL_loadScript(lua_State* L)
  346. {
  347. for (int i = cast(int)characterTextures.length; i < characterTextures.length; i++)
  348. {
  349. UnloadTexture(characterTextures[i].texture);
  350. }
  351. for (int i = cast(int)backgrounds.length; i < backgrounds.length; i++)
  352. {
  353. UnloadTexture(backgrounds[i]);
  354. }
  355. try
  356. {
  357. luaExec = luaL_checkstring(L, 1).to!string;
  358. resetAllScriptValues();
  359. }
  360. catch (Exception e)
  361. {
  362. debugWriteln(e.msg);
  363. }
  364. luaReload = true;
  365. return 0;
  366. }
  367. extern (C) nothrow int luaL_setGameState(lua_State *L) {
  368. currentGameState = cast(int)luaL_checkinteger(L, 1);
  369. return 0;
  370. }
  371. /* raylib direct bindings for graphics */
  372. /* basic */
  373. extern (C) nothrow int luaL_loadTexture(lua_State *L) {
  374. const char* fileName = luaL_checkstring(L, 1);
  375. Texture2D texture = LoadTexture(fileName);
  376. Texture2D* texturePtr = cast(Texture2D*)lua_newuserdata(L, Texture2D.sizeof);
  377. *texturePtr = texture;
  378. if (luaL_newmetatable(L, "Texture")) {
  379. lua_pushcfunction(L, &luaL_textureGC);
  380. lua_setfield(L, -2, "__gc");
  381. }
  382. lua_setmetatable(L, -2);
  383. return 1;
  384. }
  385. extern (C) nothrow int luaL_textureGC(lua_State *L) {
  386. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  387. UnloadTexture(*texture);
  388. return 0;
  389. }
  390. extern (C) nothrow int luaL_drawTexture(lua_State *L) {
  391. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  392. int x = cast(int)luaL_checkinteger(L, 2);
  393. int y = cast(int)luaL_checkinteger(L, 3);
  394. Color color = Colors.WHITE;
  395. if (lua_gettop(L) >= 4 && lua_istable(L, 4)) {
  396. lua_getfield(L, 4, "r");
  397. color.r = cast(ubyte)lua_tointeger(L, -1);
  398. lua_pop(L, 1);
  399. lua_getfield(L, 4, "g");
  400. color.g = cast(ubyte)lua_tointeger(L, -1);
  401. lua_pop(L, 1);
  402. lua_getfield(L, 4, "b");
  403. color.b = cast(ubyte)lua_tointeger(L, -1);
  404. lua_pop(L, 1);
  405. lua_getfield(L, 4, "a");
  406. color.a = cast(ubyte)lua_tointeger(L, -1);
  407. lua_pop(L, 1);
  408. }
  409. DrawTexture(*texture, x, y, color);
  410. return 0;
  411. }
  412. extern (C) nothrow int luaL_getTextureWidth(lua_State *L) {
  413. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  414. lua_pushinteger(L, texture.width);
  415. return 1;
  416. }
  417. extern (C) nothrow int luaL_getTextureHeight(lua_State *L) {
  418. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  419. lua_pushinteger(L, texture.height);
  420. return 1;
  421. }
  422. extern (C) nothrow int luaL_drawText(lua_State *L) {
  423. const char* text = luaL_checkstring(L, 1);
  424. int x = cast(int)luaL_checkinteger(L, 2);
  425. int y = cast(int)luaL_checkinteger(L, 3);
  426. int fontSize = cast(int)luaL_optinteger(L, 4, 20);
  427. Color color = Colors.WHITE;
  428. if (lua_istable(L, 5)) {
  429. lua_getfield(L, 5, "r");
  430. color.r = cast(ubyte)lua_tointeger(L, -1);
  431. lua_pop(L, 1);
  432. lua_getfield(L, 5, "g");
  433. color.g = cast(ubyte)lua_tointeger(L, -1);
  434. lua_pop(L, 1);
  435. lua_getfield(L, 5, "b");
  436. color.b = cast(ubyte)lua_tointeger(L, -1);
  437. lua_pop(L, 1);
  438. lua_getfield(L, 5, "a");
  439. color.a = cast(ubyte)lua_tointeger(L, -1);
  440. lua_pop(L, 1);
  441. }
  442. DrawTextEx(textFont, text, Vector2(x, y), fontSize, 1.0f, color);
  443. return 0;
  444. }
  445. extern (C) nothrow int luaL_measureTextX(lua_State *L) {
  446. lua_pushinteger(L, cast(int)MeasureTextEx(textFont, luaL_checkstring(L, 1), cast(int)luaL_checkinteger(L, 2), 1.0f).x);
  447. return 1;
  448. }
  449. extern (C) nothrow int luaL_measureTextY(lua_State *L) {
  450. lua_pushinteger(L, cast(int)MeasureTextEx(textFont, luaL_checkstring(L, 1), cast(int)luaL_checkinteger(L, 2), 1.0f).y);
  451. return 1;
  452. }
  453. /* extended */
  454. extern (C) nothrow int luaL_drawTextureEx(lua_State *L) {
  455. Texture2D* texture = cast(Texture2D*)luaL_checkudata(L, 1, "Texture");
  456. float x = luaL_checknumber(L, 2);
  457. float y = luaL_checknumber(L, 3);
  458. float rotation = luaL_optnumber(L, 4, 0);
  459. float scale = luaL_optnumber(L, 5, 1);
  460. Color color = Colors.WHITE;
  461. if (lua_istable(L, 6)) {
  462. lua_getfield(L, 6, "r");
  463. color.r = cast(ubyte)lua_tointeger(L, -1);
  464. lua_pop(L, 1);
  465. lua_getfield(L, 6, "g");
  466. color.g = cast(ubyte)lua_tointeger(L, -1);
  467. lua_pop(L, 1);
  468. lua_getfield(L, 6, "b");
  469. color.b = cast(ubyte)lua_tointeger(L, -1);
  470. lua_pop(L, 1);
  471. lua_getfield(L, 6, "a");
  472. color.a = cast(ubyte)lua_tointeger(L, -1);
  473. lua_pop(L, 1);
  474. }
  475. DrawTextureEx(*texture, Vector2(x, y), rotation, scale, color);
  476. return 0;
  477. }
  478. /* Register functions */
  479. extern (C) nothrow void luaL_loader(lua_State* L)
  480. {
  481. lua_register(L, "dialogBox", &luaL_dialogBox);
  482. lua_register(L, "dialogAnswerValue", &luaL_dialogAnswerValue);
  483. lua_register(L, "isDialogExecuted", &luaL_isDialogExecuted);
  484. lua_register(L, "getAnswerValue", &luaL_getAnswerValue);
  485. lua_register(L, "loadAnimationUI", &luaL_loadUIAnimation);
  486. lua_register(L, "playAnimationUI", &luaL_playUIAnimation);
  487. lua_register(L, "stopAnimationUI", &luaL_stopUIAnimation);
  488. lua_register(L, "unloadAnimationUI", &luaL_unloadUIAnimation);
  489. lua_register(L, "moveCamera", &luaL_moveCamera);
  490. lua_register(L, "isCameraMoving", &luaL_isCameraMoving);
  491. lua_register(L, "playVideo", &luaL_playVideo);
  492. lua_register(L, "loadMusic", &luaL_LoadMusic);
  493. lua_register(L, "playMusic", &luaL_PlayMusic);
  494. lua_register(L, "stopMusic", &luaL_StopMusic);
  495. lua_register(L, "playSfx", &luaL_playSfx);
  496. lua_register(L, "stopSfx", &luaL_stopSfx);
  497. lua_register(L, "Begin2D", &luaL_2dModeEnable);
  498. lua_register(L, "End2D", &luaL_2dModeDisable);
  499. lua_register(L, "load2Dcharacter", &luaL_load2Dcharacter);
  500. lua_register(L, "draw2Dcharacter", &luaL_draw2Dcharacter);
  501. lua_register(L, "stopDraw2Dcharacter", &luaL_stopDraw2Dcharacter);
  502. lua_register(L, "unload2Dcharacter", &luaL_unload2Dcharacter);
  503. lua_register(L, "load2Dtexture", &luaL_load2Dbackground);
  504. lua_register(L, "draw2Dtexture", &luaL_draw2Dbackground);
  505. lua_register(L, "stopDraw2Dtexture", &luaL_stopDraw2Dbackground);
  506. lua_register(L, "unload2Dtexture", &luaL_unload2Dbackground);
  507. lua_register(L, "getTime", &luaL_getTime);
  508. lua_register(L, "loadScript", &luaL_loadScript);
  509. lua_register(L, "setFont", &luaL_setGameFont);
  510. lua_register(L, "getScreenHeight", &luaL_getScreenHeight);
  511. lua_register(L, "getScreenWidth", &luaL_getScreenWidth);
  512. lua_register(L, "isKeyPressed", &luaL_isKeyPressed);
  513. lua_register(L, "getLanguage", &luaL_getUsedLanguage);
  514. lua_register(L, "setGameState", &luaL_setGameState);
  515. //raylib direct bindings
  516. lua_register(L, "loadTexture", &luaL_loadTexture);
  517. lua_register(L, "drawTexture", &luaL_drawTexture);
  518. lua_register(L, "drawTextureEx", &luaL_drawTextureEx);
  519. lua_register(L, "drawText", &luaL_drawText);
  520. lua_register(L, "measureTextX", &luaL_measureTextX);
  521. lua_register(L, "measureTextY", &luaL_measureTextY);
  522. lua_register(L, "getTextureWidth", &luaL_getTextureWidth);
  523. lua_register(L, "getTextureHeight", &luaL_getTextureHeight);
  524. }
  525. int luaInit(string luaExec)
  526. {
  527. debugWriteln("loading Lua");
  528. L = luaL_newstate();
  529. luaL_openlibs(L);
  530. luaL_loader(L);
  531. debugWriteln("Executing next Lua file: ", luaExec);
  532. if (std.file.exists(luaExec) == false) {
  533. debugWriteln("Script file not found! Exiting.");
  534. return EngineExitCodes.EXIT_FILE_NOT_FOUND;
  535. }
  536. if (luaL_dofile(L, toStringz(luaExec)) != LUA_OK) {
  537. debugWriteln("Lua error: ", to!string(lua_tostring(L, -1)));
  538. return EngineExitCodes.EXIT_SCRIPT_ERROR;
  539. }
  540. return EngineExitCodes.EXIT_OK;
  541. }
  542. void luaEventLoop()
  543. {
  544. lua_getglobal(L, "EventLoop");
  545. if (lua_pcall(L, 0, 0, 0) != LUA_OK)
  546. {
  547. debug debugWriteln("Error in EventLoop: ", to!string(lua_tostring(L, -1)));
  548. }
  549. lua_pop(L, 0);
  550. }