diff options
author | chai <chaifix@163.com> | 2018-11-12 08:04:11 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-11-12 08:04:11 +0800 |
commit | 72e45f0062d727cedd576d1e1251f6722454a119 (patch) | |
tree | 736594b79e71c66a668d99d96c3ce464618e50ca /src/lua/common/je_lua_reference.h | |
parent | 7c2f33bdf37de7acf9b0728a115377081344db1c (diff) |
*修改代码结构
Diffstat (limited to 'src/lua/common/je_lua_reference.h')
-rw-r--r-- | src/lua/common/je_lua_reference.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lua/common/je_lua_reference.h b/src/lua/common/je_lua_reference.h new file mode 100644 index 0000000..28c3bc3 --- /dev/null +++ b/src/lua/common/je_lua_reference.h @@ -0,0 +1,52 @@ +#ifndef __JIN_COMMON_REFERENCE_H +#define __JIN_COMMON_REFERENCE_H + +#include "../luax.h" + +namespace JinEngine +{ + namespace Lua + { + + /// + /// This class wraps the reference functionality built into Lua, which allows C++ code to refer to Lua + /// variables. + /// + class Reference + { + public: + Reference(lua_State* L, unsigned int i) + : mL(L) + { + luax_pushvalue(mL, i); + mIndex = luax_ref(mL, LUA_REGISTRYINDEX); + } + + ~Reference() + { + unref(); + } + + void unref() + { + luax_unref(mL, LUA_REGISTRYINDEX, mIndex); + } + + /// + /// Push value onto the stack. + /// + void push() + { + luax_rawgeti(mL, LUA_REGISTRYINDEX, mIndex); + } + + private: + lua_State* const mL; + int mIndex; + + }; + + } // namespace Lua +} // namespace JinEngine + +#endif // __JIN_COMMON_REFERENCE_H
\ No newline at end of file |