/TGame/TUtil/Lua/LuaWrapper.h

http://awoe.googlecode.com/ · C Header · 82 lines · 57 code · 16 blank · 9 comment · 0 complexity · 1426d8d311d0773b3aa995575bc423ca MD5 · raw file

  1. #ifndef __LUA_WRAPPER__
  2. #define __LUA_WRAPPER__
  3. #include "Entry/TExportUtil.h"
  4. extern "C"
  5. {
  6. #include "lua.h"
  7. #include "lualib.h"
  8. #include "lauxlib.h"
  9. }
  10. class TUTIL_API Lua
  11. {
  12. public:
  13. Lua(lua_State* pState);
  14. Lua();
  15. virtual ~Lua();
  16. static Lua* instance();
  17. lua_State* state();
  18. void load(const char *libname, const luaL_Reg *l);
  19. bool getglobal(const char* name, bool& val);
  20. bool getglobal(const char* name, int& val);
  21. bool getglobal(const char* name, float& val);
  22. bool getglobal(const char* name, string& val);
  23. bool setglobal(const char* name, bool val);
  24. bool setglobal(const char* field, int val);
  25. bool setglobal(const char* field, float val);
  26. bool setglobal(const char* field, const char* fmt, ...);
  27. bool setglobal(const char* field, const string& val);
  28. bool table(const char* name);
  29. bool setfield();
  30. bool setfield(const char* field, int val);
  31. bool setfield(const char* field, float val);
  32. bool setfield(const char* field, const char* fmt, ...);
  33. bool setfield(const char* field, const string& val);
  34. bool setfield(int field, int val);
  35. bool setfield(int field, float val);
  36. bool setfield(int field, const char* fmt, ...);
  37. bool getfield(const char* field, int& val);
  38. bool getfield(const char* field, float& val);
  39. bool getfield(const char* field, string& val);
  40. //
  41. // execute a lua code block
  42. bool call(const char* code);
  43. //
  44. // execute a lua function with specific input parameters in the stack and specific ouput paramter back in the stack
  45. bool call(const char* func, int narg, int nres = 0);
  46. //
  47. // execute a lua function with specific input parameters in the stack and specific ouput paramter back in the stack
  48. bool call(const char* ns, const char* func, int narg, int nres = 0);
  49. //
  50. // execute a lua function with any input parameter and output parameter
  51. //bool call(const char* func, const char* sig, ...);
  52. bool push(int val);
  53. bool push(float val);
  54. bool push(const char* val);
  55. bool push(const char* fmt, ...);
  56. bool push(const string& val);
  57. bool push_global(const char* val);
  58. bool pop();
  59. bool pop(bool& val);
  60. bool pop(int& val);
  61. bool pop(float& val);
  62. bool pop(string& val);
  63. protected:
  64. lua_State* m_pState;
  65. };
  66. #endif