diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/3rdParty/Luax/luax.h | 3 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_class.cpp | 32 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_class.h | 95 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_config.h | 3 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_memberref.cpp | 0 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_memberref.h | 17 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_ref.h | 19 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_reftable.cpp | 120 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_reftable.h | 65 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_runtime.cpp | 97 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_runtime.h | 64 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_state.cpp | 26 | ||||
-rw-r--r-- | Source/3rdParty/Luax/luax_state.h | 41 | ||||
-rw-r--r-- | Source/Asura.Engine/Graphics/Image.h | 3 | ||||
-rw-r--r-- | Source/Asura.Engine/Graphics/Port/Shader.cpp | 28 | ||||
-rw-r--r-- | Source/Samples/LuaxTest/main.cpp | 29 |
16 files changed, 562 insertions, 80 deletions
diff --git a/Source/3rdParty/Luax/luax.h b/Source/3rdParty/Luax/luax.h index 66162a4..f43fb26 100644 --- a/Source/3rdParty/Luax/luax.h +++ b/Source/3rdParty/Luax/luax.h @@ -4,11 +4,12 @@ // moai-coreг // include lua.hpp before this -#include "luax_runtime.h" #include "luax_state.h" #include "luax_ref.h" #include "luax_class.h" #include "luax_module.h" +#include "luax_runtime.h" +#include "luax_reftable.h" // luax չluaҪ // * modules diff --git a/Source/3rdParty/Luax/luax_class.cpp b/Source/3rdParty/Luax/luax_class.cpp index 99da697..52cf6b7 100644 --- a/Source/3rdParty/Luax/luax_class.cpp +++ b/Source/3rdParty/Luax/luax_class.cpp @@ -1,27 +1,33 @@ #include "luax_state.h" #include "luax_class.h" +#include "luax_runtime.h" namespace Luax { LuaxClass::LuaxClass() - : mRefCount(1) // ʱĬһ + : mRC(1) // ʱĬһ + , mSafer(false) { } LuaxClass::~LuaxClass() { + assert(mSafer); } void LuaxClass::Retain() { - ++mRefCount; + ++mRC; } void LuaxClass::Release() { - if (--mRefCount <= 0) + if (--mRC <= 0) + { + mSafer = true; // safer delete this; + } } bool LuaxClass::PushLuaUserdata(LuaxState& state) @@ -29,9 +35,20 @@ namespace Luax return true; } - void LuaxClass::BindToLua(LuaxState& state) + void LuaxClass::BindFactoryToLua(LuaxState& state) + { + //assert(!mUserdata); + + // + state.PushPtrUserData(this); + + lua_newtable(state); // ref table + lua_newtable(state); // member table + + } + + void LuaxClass::BindSingletonToLua(LuaxState& state) { - assert(!mUserdata); } @@ -47,4 +64,9 @@ namespace Luax return 0; } + int LuaxClass::l_ToString(lua_State* L) + { + return 0; + } + }
\ No newline at end of file diff --git a/Source/3rdParty/Luax/luax_class.h b/Source/3rdParty/Luax/luax_class.h index d241030..bde9990 100644 --- a/Source/3rdParty/Luax/luax_class.h +++ b/Source/3rdParty/Luax/luax_class.h @@ -6,6 +6,7 @@ #include "lua.hpp" #include "luax_config.h" #include "luax_state.h" +#include "luax_runtime.h" namespace Luax { @@ -46,55 +47,80 @@ namespace Luax void Retain(); void Release(); - //------------------------------------------------------------------------------------------------------------ - // + protected: - template<class T> - static void RegisterLuaxClass(LuaxState& state); + LuaxClass(); + virtual ~LuaxClass(); - template<class T> - LUAX_DECL_METHOD(l_GetClassName); + /// + /// userdata pushջûгʼmUserdataʼúԪѳʼõuserdataջ + /// + bool PushLuaUserdata(LuaxState& state); //------------------------------------------------------------------------------------------------------------ - // - template<class T> - static void RegisterLuaxFactoryClass(LuaxState& state); + /// + /// reftableĹ + /// + void Ref(); - template<class T> - static void RegisterLuaxInterface(LuaxState& state); + private: - LUAX_DECL_METHOD(l_GC); + friend class LuaxState; - //------------------------------------------------------------------------------------------------------------ - // + template<class T> static void RegisterLuaxClass(LuaxState& state); + template<class T> static void RegisterLuaxFactoryClass(LuaxState& state); + template<class T> static void RegisterLuaxInterface(LuaxState& state); + template<class T> static void RegisterLuaxSingletonClass(LuaxState& state); - template<class T> - static void RegisterLuaxSingletonClass(LuaxState& state); + /// + /// ȡַҪַֻͨڶϴʵõջϺ;̬ıȡַ֤üȷ + /// ҪãʹôݶǴݵַ + /// + void* operator &(); - protected: + /// + /// stateǹ + /// + void BindFactoryToLua(LuaxState& state); - LuaxClass(); - ~LuaxClass(); + /// + /// stateǵ + /// + void BindSingletonToLua(LuaxState& state); + + //------------------------------------------------------------------------------------------------------------ + + LuaxStrongRef mInterfaceTable; // interface table + LuaxStrongRef mClassTable; // class table /// - /// userdata pushջûгʼmUserdataʼúԪѳʼõuserdataջ + /// ü̼߳乲 /// - bool PushLuaUserdata(LuaxState& state); - - private: + int mRC; /// - /// ȡַҪַֻͨڶϴʵõջϺ;̬ıȡַ֤üȷ - /// ҪãʹôݶǴݵַ + /// ȷֻͨReleaseõsaferֻҪ̳LuaxClass࣬ʹdeleteֱͻᱨ /// - void* operator &(); + bool mSafer; - void BindToLua(LuaxState& state); + public: - int mRefCount; + //------------------------------------------------------------------------------------------------------------ + // + + template<class T> LUAX_DECL_METHOD(l_GetClassName); + template<class T> LUAX_DECL_METHOD(l_GetClassName2); + + LUAX_DECL_METHOD(l_ToString); // __tostring + + //------------------------------------------------------------------------------------------------------------ + // - void* mUserdata; + LUAX_DECL_METHOD(l_GC); // __gc + + //------------------------------------------------------------------------------------------------------------ + // }; @@ -102,8 +128,15 @@ namespace Luax /// ڳԱﴴLuaxStateԲм顣 /// #define LUAX_SETUP(L, params) \ - LuaxState state(L);\ - if(!state.CheckParams(1, params)) return 0; + LuaxRuntime& runtime = LuaxRuntime::Get(); \ + LuaxState& state = runtime[L].state; \ + if(!state.CheckParams(1, params)) return 0 + +#define LUAX_STATE(L) \ + LuaxState& state = LuaxRuntime::Get().GetLuaxState(L) + +#define LUAX_RUNTIME() \ + LuaxRuntime& runtime = LuaxRuntime::Get() #include "luax_class.inl" diff --git a/Source/3rdParty/Luax/luax_config.h b/Source/3rdParty/Luax/luax_config.h index a33750f..ea623a9 100644 --- a/Source/3rdParty/Luax/luax_config.h +++ b/Source/3rdParty/Luax/luax_config.h @@ -1,6 +1,9 @@ #ifndef __LUAX_TYPE_H__ #define __LUAX_TYPE_H__ +#include <iostream> +#include "lua.hpp" + #include <assert.h> namespace Luax diff --git a/Source/3rdParty/Luax/luax_memberref.cpp b/Source/3rdParty/Luax/luax_memberref.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/3rdParty/Luax/luax_memberref.cpp diff --git a/Source/3rdParty/Luax/luax_memberref.h b/Source/3rdParty/Luax/luax_memberref.h new file mode 100644 index 0000000..052c53e --- /dev/null +++ b/Source/3rdParty/Luax/luax_memberref.h @@ -0,0 +1,17 @@ +#ifndef __LUAX_MEMBER_REF_H__ +#define __LUAX_MEMBER_REF_H__ + +namespace Luax +{ + + /// + /// LuaxClassijԱã֤ȷͷţǿá + /// + class LuaxMemberRef + { + + }; + +} + +#endif
\ No newline at end of file diff --git a/Source/3rdParty/Luax/luax_ref.h b/Source/3rdParty/Luax/luax_ref.h index 122c448..759a314 100644 --- a/Source/3rdParty/Luax/luax_ref.h +++ b/Source/3rdParty/Luax/luax_ref.h @@ -5,18 +5,35 @@ namespace Luax { /// - /// Lua referenceLUA_REGISTRYINDEXĴ档 + /// ãLUA_REGISTRYINDEX /// class LuaxRef { + public: + + enum + { + STRONG, + WEAK + }; + + private: + + int mRefID; // = luaL_ref }; + /// + /// ǿãLUA_REGISTRYINDEX["LUAX_STRONGREF_TABLE"] + /// class LuaxStrongRef: public LuaxRef { }; + /// + /// ãLUA_REGISTRYINDEX["LUAX_WEAKREF_TABLE"] + /// class LuaxWeakRef : public LuaxRef { diff --git a/Source/3rdParty/Luax/luax_reftable.cpp b/Source/3rdParty/Luax/luax_reftable.cpp new file mode 100644 index 0000000..602c9eb --- /dev/null +++ b/Source/3rdParty/Luax/luax_reftable.cpp @@ -0,0 +1,120 @@ +#include "luax_reftable.h" +#include "luax_state.h" + +namespace Luax +{ + + LuaxRefTable::LuaxRefTable() + : mState(nullptr) + { + } + + LuaxRefTable::~LuaxRefTable() + { + } + + void LuaxRefTable::Init(LuaxState& state, cc8* name, cc8* mode) + { + assert(!mState); + assert(name); + + mName = name; + mMode = 0; + for (int i = 0; mode && mode[i]; ++i) + { + if (mode[i] == 'k') mMode |= WEAK_KEY; + else if (mode[i] == 'v') mMode |= WEAK_VALUE; + } + mState = state.GetHandle(); + + state.GetField(LUA_REGISTRYINDEX, name); // register[mName] + if (state.IsNil(-1)) + { + state.Pop(); + + lua_newtable(state); // ref table + int ridx = state.AbsIndex(-1); + lua_newtable(state); // metatable of ref table + int idx = state.AbsIndex(-1); + + // __mode + if (mode) + { + state.Push(mode); + state.SetField(idx, "__mode"); + } + + state.Settop(idx); + lua_setmetatable(state, ridx); + + state.Settop(ridx); + state.SetField(LUA_REGISTRYINDEX, name); + } + else + { + state.Pop(); + } + } + + bool LuaxRefTable::IsKeyWeak() + { + assert(mState); + + return mMode & WEAK_KEY; + } + + bool LuaxRefTable::IsValueWeak() + { + assert(mState); + + return mMode & WEAK_VALUE; + } + + int LuaxRefTable::Ref(LuaxState& state, int idx) + { + assert(mState && mState == state.GetHandle()); + + idx = state.AbsIndex(idx); + state.GetField(LUA_REGISTRYINDEX, mName); // ref table + lua_pushvalue(state, idx); // stuff + int refID = luaL_ref(state, -2); + assert(refID != LUA_NOREF); + state.Pop(); + return refID; + } + + void LuaxRefTable::Unref(LuaxState& state, int refID) + { + assert(mState && mState == state.GetHandle()); + + state.GetField(LUA_REGISTRYINDEX, mName); // ref table + luaL_unref(state, -1, refID); + state.Pop(); + return; + } + + void LuaxRefTable::PushRefTable(LuaxState& state) + { + assert(mState && mState == state.GetHandle()); + + lua_getfield(state, LUA_REGISTRYINDEX, mName); + } + + void LuaxRefTable::PushRef(LuaxState& state, int refID) + { + assert(mState && mState == state.GetHandle()); + + lua_getfield(state, LUA_REGISTRYINDEX, mName); + lua_rawgeti(state, -1, refID); + lua_replace(state, -2); + } + + void LuaxRefTable::Clear(LuaxState& state) + { + assert(mState && mState == state.GetHandle()); + + lua_newtable(state); + state.SetField(LUA_REGISTRYINDEX, mName); + } + +}
\ No newline at end of file diff --git a/Source/3rdParty/Luax/luax_reftable.h b/Source/3rdParty/Luax/luax_reftable.h new file mode 100644 index 0000000..0ba42f7 --- /dev/null +++ b/Source/3rdParty/Luax/luax_reftable.h @@ -0,0 +1,65 @@ +#ifndef __LUAX_REFTABLE_H__ +#define __LUAX_REFTABLE_H__ + +#include "luax_config.h" + +namespace Luax +{ + + class LuaxState; + + /// + /// ref table strong ref tableweak ref tabletableĴ + /// + class LuaxRefTable + { + public: + + enum + { + WEAK_KEY = 1, + WEAK_VALUE = 1 << 1 + }; + + LuaxRefTable(); + ~LuaxRefTable(); + + void Init(LuaxState& state, cc8* name, cc8* mode = nullptr); + + bool IsKeyWeak(); + bool IsValueWeak(); + + /// + /// stack[idx]ʵڴref tableһãrefID + /// + int Ref(LuaxState& state, int idx); + void Unref(LuaxState& state, int refID); + + /// + /// ref table ջ + /// + void PushRefTable(LuaxState& state); + + /// + /// reftable[refID] ջ + /// + void PushRef(LuaxState& state, int refID); + + /// + /// ref tableLUA_REGISTRYINDEX[mName] + /// + void Clear(LuaxState& state); + + private: + + friend class LuaxState; + + lua_State* mState; // һЩȷϹ + cc8* mName; // ref table + int mMode; // ref table + + }; + +} + +#endif
\ No newline at end of file diff --git a/Source/3rdParty/Luax/luax_runtime.cpp b/Source/3rdParty/Luax/luax_runtime.cpp index e69de29..1c5becb 100644 --- a/Source/3rdParty/Luax/luax_runtime.cpp +++ b/Source/3rdParty/Luax/luax_runtime.cpp @@ -0,0 +1,97 @@ +#ifndef __LUAX_RUNTIME_H_ +#define __LUAX_RUNTIME_H_ + +#include "luax_runtime.h" + +using namespace std; + +namespace Luax +{ + + Context::Context(lua_State* L) + : state(L) + { + strongRefTable.Init(state, "LUAX_STRONGREF_TABLE"); + weakRefTable.Init(state, "LUAX_WEAKREF_TABLE", "v"); + } + + Context::~Context() + { + } + + //-------------------------------------------------------------------------------------------------------------- + + LuaxRuntime* LuaxRuntime::mRuntime = nullptr; + + LuaxRuntime::LuaxRuntime() {}; + LuaxRuntime::~LuaxRuntime() {}; + + LuaxRuntime& LuaxRuntime::Get() + { + if (mRuntime == nullptr) + mRuntime = new LuaxRuntime(); + + return *mRuntime; + } + + lua_State* LuaxRuntime::Open() + { + lua_State* L = lua_open(); + assert(L); + mContexts.insert(pair<lua_State*, Context>(L, Context(L))); + return L; + } + + void LuaxRuntime::Close(lua_State* L) + { + map<lua_State*, Context>::iterator it = mContexts.find(L); + if (it != mContexts.end()) + { + lua_close(it->second.state); + mContexts.erase(it); + } + } + + bool LuaxRuntime::HasLuaxState(lua_State* L) + { + map<lua_State*, Context>::iterator it = mContexts.find(L); + return it != mContexts.end(); + } + + LuaxState& LuaxRuntime::GetLuaxState(lua_State* L) + { + map<lua_State*, Context>::iterator it = mContexts.find(L); + if (it != mContexts.end()) + { + return it->second.state; + } + } + + LuaxRefTable& LuaxRuntime::GetStrongRefTable(lua_State* L) + { + map<lua_State*, Context>::iterator it = mContexts.find(L); + if (it != mContexts.end()) + { + return it->second.strongRefTable; + } + } + + LuaxRefTable& LuaxRuntime::GetWeaksRefTable(lua_State* L) + { + map<lua_State*, Context>::iterator it = mContexts.find(L); + if (it != mContexts.end()) + { + return it->second.weakRefTable; + } + } + + Context& LuaxRuntime::operator[](lua_State* L) + { + map<lua_State*, Context>::iterator it = mContexts.find(L); + assert(it != mContexts.end()); + return it->second; + } + +} + +#endif
\ No newline at end of file diff --git a/Source/3rdParty/Luax/luax_runtime.h b/Source/3rdParty/Luax/luax_runtime.h index 94d8ecc..2414c2e 100644 --- a/Source/3rdParty/Luax/luax_runtime.h +++ b/Source/3rdParty/Luax/luax_runtime.h @@ -1,13 +1,69 @@ #ifndef __LUAX_RUNTIME_H__ #define __LUAX_RUNTIME_H__ -namespace Luax +#include <map> + +#include "luax_config.h" +#include "luax_state.h" + +namespace Luax { - enum RegisterIndex + /// + /// lua_stateصcontextһϵдļϣҲûϵҪΪ˽Լڴ档 + /// + class Context { - LUAX_OBJECT_INDEX = 1, - LUAX_OBJECT_MODULE = 2, + public: + Context(lua_State* L); + ~Context(); + + LuaxState state; // lua state + LuaxRefTable strongRefTable; // strong ref table + LuaxRefTable weakRefTable; // weak ref table + + size_t objectCount; // ͳڴstateдʵ + + }; + + /// + /// ͳһеlua states + /// + class LuaxRuntime + { + public: + + static LuaxRuntime& Get(); + + /// + /// һµlua_Stateصlua_State*һ8\4ֽڵkey + /// + lua_State* Open(); + + /// + /// رlua_Stateruntimeɾ + /// + void Close(lua_State* L); + + bool HasLuaxState(lua_State* L); + LuaxState& GetLuaxState(lua_State* L); + LuaxRefTable& GetStrongRefTable(lua_State* L); + LuaxRefTable& GetWeaksRefTable(lua_State* L); + + Context& operator[](lua_State* L); + + private: + + LuaxRuntime(); + ~LuaxRuntime(); + + static LuaxRuntime* mRuntime; + + /// + /// lua_stateҵcontext + /// + std::map<lua_State*, Context> mContexts; + }; } diff --git a/Source/3rdParty/Luax/luax_state.cpp b/Source/3rdParty/Luax/luax_state.cpp index a92d697..87c3bcd 100644 --- a/Source/3rdParty/Luax/luax_state.cpp +++ b/Source/3rdParty/Luax/luax_state.cpp @@ -11,6 +11,12 @@ namespace Luax assert(state); } + LuaxState::LuaxState(const LuaxState& state) + : L(state.mState) + { + assert(state.mState); + } + LuaxState::~LuaxState() { } @@ -35,6 +41,11 @@ namespace Luax return *L; } + lua_State* LuaxState::GetHandle() + { + return L; + } + void LuaxState::OpenLibs() { luaL_openlibs(L); @@ -72,8 +83,14 @@ namespace Luax int LuaxState::AbsIndex(int idx) { +/* +#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ + lua_gettop(L) + (i) + 1) +*/ if (idx < 0) { - return lua_gettop(L) + idx + 1; + //return lua_gettop(L) + idx + 1; + return ((idx) > 0 || (idx) <= LUA_REGISTRYINDEX ? (idx) : \ + lua_gettop(L) + (idx)+1); } return idx; } @@ -83,7 +100,7 @@ namespace Luax return 0; } - void LuaxState::Push() + void LuaxState::PushNil() { lua_pushnil(L); } @@ -153,6 +170,11 @@ namespace Luax lua_pop(L, n); } + void LuaxState::Settop(int idx) + { + lua_settop(L, idx); + } + bool LuaxState::IsNil(int idx) { return lua_isnil(L, idx); diff --git a/Source/3rdParty/Luax/luax_state.h b/Source/3rdParty/Luax/luax_state.h index 52b8f38..6a688b6 100644 --- a/Source/3rdParty/Luax/luax_state.h +++ b/Source/3rdParty/Luax/luax_state.h @@ -4,33 +4,37 @@ #include <string> #include "lua.hpp" +#include "luax_reftable.h" #include "luax_config.h" namespace Luax { + class Context; class LuaxClass; /// /// lua_StateĴ˱һlua_Stateòݡһʵmetatable£ - /// interface table - /// member table - /// ref table - /// userdata + /// interface table + /// member table + /// ref table + /// userdata /// userdataͨgetmetatableȡϼmetatable֮һclass tableעڶӦƿռ /// LUAX_API class LuaxState { public: - LuaxState(lua_State* state); - ~LuaxState(); - operator lua_State*(); operator bool(); lua_State* operator ->(); lua_State& operator *(); - + + /// + /// ȡlua_State + /// + lua_State* GetHandle(); + //------------------------------------------------------------------------------------------------------------ void OpenLibs(); @@ -82,7 +86,7 @@ namespace Luax bool HasField(int idx, int name, int type); bool HasKeys(int idx); - void Push(); + void PushNil(); void Push(bool value); void Push(cc8* value); void Push(double value); @@ -103,6 +107,13 @@ namespace Luax void Pop(int n = 1); + void Settop(int idx); + + //------------------------------------------------------------------------------------------------------------ + // õĹregister[LUAX_STRONG_REFTABLE]register[LUAX_WEAK_REFTABLE] + + void Ref(); + //------------------------------------------------------------------------------------------------------------ template<typename T> T GetValue(int idx, T default_value); @@ -121,17 +132,21 @@ namespace Luax /// /// עṤͨ࣬New /// - template<typename T> - void RegisterFactory(); + template<typename T> void RegisterFactory(); /// /// עᵥûNew /// - template<typename T> - void RegisterSingleton(); + template<typename T> void RegisterSingleton(); private: + friend class Context; + + LuaxState(lua_State* state); + LuaxState(const LuaxState& state); + ~LuaxState(); + /// /// ζLuaxStateĵַز /// diff --git a/Source/Asura.Engine/Graphics/Image.h b/Source/Asura.Engine/Graphics/Image.h index 6d12303..66c7ae1 100644 --- a/Source/Asura.Engine/Graphics/Image.h +++ b/Source/Asura.Engine/Graphics/Image.h @@ -2,6 +2,7 @@ #define __ASURA_ENGINE_IMAGE_H__ #include "Math/Vector2.hpp" +#include "Scripting/Portable.h" #include "FileSystem/Reloadable.h" #include "StringMap.hpp" #include "Manager.hpp" @@ -61,7 +62,7 @@ namespace AsuraEngine //---------------------------------------------------------------------------------------------------------- LUAX_DECL_FACTORY(SimImage); - + LUAX_DECL_METHOD(l_Load); LUAX_DECL_METHOD(l_GetWidth); LUAX_DECL_METHOD(l_GetHeight); diff --git a/Source/Asura.Engine/Graphics/Port/Shader.cpp b/Source/Asura.Engine/Graphics/Port/Shader.cpp index 2253a56..35fa86d 100644 --- a/Source/Asura.Engine/Graphics/Port/Shader.cpp +++ b/Source/Asura.Engine/Graphics/Port/Shader.cpp @@ -12,7 +12,7 @@ namespace AsuraEngine /// int Shader::l_Use(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } @@ -21,7 +21,7 @@ namespace AsuraEngine /// int Shader::l_Unuse(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } @@ -30,7 +30,7 @@ namespace AsuraEngine /// int Shader::l_Load(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } @@ -39,7 +39,7 @@ namespace AsuraEngine /// int Shader::l_HasUniform(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } @@ -48,56 +48,54 @@ namespace AsuraEngine /// int Shader::l_GetUniformLocation(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } int Shader::l_SetBuiltInUniforms(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } int Shader::l_SetUniformFloat(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } int Shader::l_SetUniformTexture(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } int Shader::l_SetUniformVector2(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } int Shader::l_SetUniformVector3(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } int Shader::l_SetUniformVector4(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } int Shader::l_SetUniformColor(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); } - //עluaijԱ - int Shader::RegisterLuaClass(lua_State* L) + void Shader::RegisterLuaxClass(LuaxState& state) { - LuaxState state(L); } diff --git a/Source/Samples/LuaxTest/main.cpp b/Source/Samples/LuaxTest/main.cpp index 828b427..8dc7281 100644 --- a/Source/Samples/LuaxTest/main.cpp +++ b/Source/Samples/LuaxTest/main.cpp @@ -36,7 +36,7 @@ public: int School::l_GetName(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); School* school = Get(); @@ -84,7 +84,7 @@ public: int Boy::l_New(lua_State* L) { - LuaxState state(L); + LUAX_STATE(L); int age = state.GetValue(1, 0); @@ -97,7 +97,6 @@ int Boy::l_New(lua_State* L) int Boy::l_GetAge(lua_State* L) { LUAX_SETUP(L, "U"); - return 1; } @@ -149,6 +148,19 @@ function main() print(Asura.SimBoy.GetClassName()) print(Asura.School.GetName()) print(Asura.School.Region) +--[[ + local Kid = Asura.SimBoy.Extend() + Asura.Kid = Kid + Kid.New = function(self, height, age) + self.base(age) + self.height = height + end + Kid.GetHeight = function(self) + print(self.height) + end + local kid = Kid.New(110, 12) + kid:GetHeight() +]] end function err(msg) print(msg) @@ -167,8 +179,11 @@ int func(lua_State* L) int main() { - lua_State* L = lua_open(); - Luax::LuaxState state(L); + LuaxRuntime& runtime = LuaxRuntime::Get(); + lua_State* L = runtime.Open(); + + Luax::LuaxState& state = runtime[L].state; + LuaxRefTable& strong = runtime[L].strongRefTable; state.OpenLibs(); state.PushNamespace("Asura"); state.PushNamespace("author"); @@ -183,8 +198,8 @@ int main() state.PopNamespace(); // Asura state.DoString(script); - - lua_close(L); + + runtime.Close(L); getchar(); }
\ No newline at end of file |