diff options
author | chai <chaifix@163.com> | 2019-03-16 13:03:50 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-03-16 13:03:50 +0800 |
commit | 1ab2501db0f9e14f138292880e37120e7a6184de (patch) | |
tree | 2d1cfa82a9a6a3a0f16e516f100b2acb6f7e0e4e /Source/Samples/LuaxTest/main.cpp | |
parent | 95d27af75eb2aff8020e073eff8dfeb074b5bba6 (diff) |
*luax
Diffstat (limited to 'Source/Samples/LuaxTest/main.cpp')
-rw-r--r-- | Source/Samples/LuaxTest/main.cpp | 64 |
1 files changed, 5 insertions, 59 deletions
diff --git a/Source/Samples/LuaxTest/main.cpp b/Source/Samples/LuaxTest/main.cpp index 3d5eb34..63daa1c 100644 --- a/Source/Samples/LuaxTest/main.cpp +++ b/Source/Samples/LuaxTest/main.cpp @@ -93,7 +93,7 @@ int Boy::l_New(lua_State* L) const char* name = state.GetValue(2, ""); Boy* boy = new Boy(age, name); - boy->PushLuaUserdata(state); + boy->PushLuaxUserdata(state); return 1; } @@ -179,64 +179,8 @@ class Girl : public LuaxClass<Girl> }; //---------------------------------------------------------------------------------------------------------------- -string script = R"( -function main() - local a = 19 - print(Asura.version) - print(Asura.author.name) - print("ok") - print(Asura.author.func()) --- local boy = Asura.SimBoy.New("I am peter!", 19) --- boy:Say() --- print(Asura.SimSchool.GetName()) - print(Asura.SimBoy.Class) - print(Asura.SimBoy.Gender) - 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() - ]] - local kid = Asura.SimBoy.New(23, "Chai") - print(kid:GetAge()) - print(kid:GetName()) - kid.fruit = function() - return "apple" - end - print(kid.fruit()) - print(Asura.SimBoy.GetGender()) - Asura.SimBoy.Havefun = function() - return "Boys have some fun!" - end - print(Asura.SimBoy.Havefun()) - --- - Asura.SimBoy.Foo = function() - return "SimBoy.Foo" - end - print(Asura.SimBoy.Foo()) - - print(Asura.EGender.BOY) - Asura.EGender.BOY = 2 - print(Asura.EGender.BOY) - print(Asura.SimBoy.EHabits.Girls) - print(Asura.EHabits.Girls) -end -function err(msg) - print(msg) -end -xpcall(main, err) -)"; + +#include "script.lua" //---------------------------------------------------------------------------------------------------------------- @@ -254,6 +198,7 @@ int main() Luax::LuaxState& state = runtime[L].state; state.OpenLibs(); + state.PushGlobalNamespace(); state.PushNamespace("Asura"); //עenum @@ -277,6 +222,7 @@ int main() state.RegisterFactory<Boy>(); state.PopNamespace(); // Asura + state.PopNamespace(); // Global state.DoString(script); runtime.Close(L); |