PageRenderTime 46ms CodeModel.GetById 21ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

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