Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "ZLua.h"
  3.  
  4. ZLua::ZLua()
  5. {
  6.  
  7.  
  8. for (auto& obj : m_luaStates)
  9. {
  10. delete obj.second;
  11. obj.second = nullptr;
  12. }
  13. m_luaStates.clear();
  14.  
  15. }
  16.  
  17. ZLua::~ZLua()
  18. {
  19. }
  20.  
  21. //always close after executing script
  22. void ZLua::Close()
  23. {
  24. lua_close(state);
  25. }
  26.  
  27.  
  28. void ZLua::Create()
  29. {
  30. state = luaL_newstate();
  31. luaL_openlibs(state);
  32. }
  33.  
  34. bool ZLua::loadScript(const char* scriptName)
  35. {
  36. TCHAR currDir[MAX_PATH];
  37. GetCurrentDirectory(MAX_PATH, currDir);
  38.  
  39. strcat(currDir, "\\");
  40. strcat(currDir, scriptName);
  41.  
  42. if (luaL_dofile(state, currDir)) {
  43. mlog("Error Loading Script - %s\n", lua_tostring(state,-1));
  44. return false;
  45. }
  46.  
  47. //m_luaStates.emplace(scriptName,state);
  48.  
  49. return true;
  50.  
  51. }
  52.  
  53. bool ZLua::LToC(const char* scriptName)
  54. {
  55.  
  56. }
  57.  
  58. void ZLua::Bind(const char* scriptName, lua_CFunction func)
  59. {
  60. lua_State* state = luaL_newstate();
  61. lua_register(state, scriptName, func);
  62. m_luaStates.emplace(scriptName,state);
  63. }
  64.  
  65. void ZLua::Run(const char* scriptName)
  66. {
  67. lua_State* state = m_luaStates.find(scriptName)->second;
  68. luaL_dofile(state, scriptName);
  69. lua_close(state);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement