lua.cpp 575 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "Crown.h"
  2. #include "Game.h"
  3. namespace crown
  4. {
  5. lua_State* L;
  6. void init()
  7. {
  8. L = luaL_newstate();
  9. luaL_openlibs(L);
  10. lua_cpcall(L, luaopen_libcrownlua, NULL);
  11. if (luaL_loadfile(L, "/home/mikymod/test/res_linux/lua/game.raw") || lua_pcall(L, 0, 0, 0))
  12. {
  13. os::printf("error: %s", lua_tostring(L, -1));
  14. }
  15. lua_getglobal(L, "init");
  16. lua_pcall(L, 0, 0, 0);
  17. }
  18. void shutdown()
  19. {
  20. lua_getglobal(L, "shutdown");
  21. lua_pcall(L, 0, 0, 0);
  22. lua_close(L);
  23. }
  24. void frame(float dt)
  25. {
  26. lua_getglobal(L, "frame");
  27. lua_pushnumber(L, dt);
  28. lua_pcall(L, 1, 0, 0);
  29. }
  30. }