Game.cpp 690 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "Crown.h"
  2. #include "Game.h"
  3. #include "lua.hpp"
  4. namespace crown
  5. {
  6. StringSetting g_boot("boot_file", "lua main file", "lua/game.raw");
  7. lua_State* L;
  8. void init()
  9. {
  10. L = luaL_newstate();
  11. luaL_openlibs(L);
  12. lua_cpcall(L, luaopen_libcrown, NULL);
  13. const char* path = device()->filesystem()->os_path(g_boot.value());
  14. if (luaL_loadfile(L, path) || lua_pcall(L, 0, 0, 0))
  15. {
  16. os::printf("error: %s", lua_tostring(L, -1));
  17. }
  18. lua_getglobal(L, "init");
  19. lua_pcall(L, 0, 0, 0);
  20. }
  21. void shutdown()
  22. {
  23. lua_getglobal(L, "shutdown");
  24. lua_pcall(L, 0, 0, 0);
  25. lua_close(L);
  26. }
  27. void frame(float dt)
  28. {
  29. lua_getglobal(L, "frame");
  30. lua_pushnumber(L, dt);
  31. lua_pcall(L, 1, 0, 0);
  32. }
  33. }