From 1ab2501db0f9e14f138292880e37120e7a6184de Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 16 Mar 2019 13:03:50 +0800 Subject: *luax --- Source/Samples/LuaxTest/main.cpp | 64 ++++------------------------------------ 1 file changed, 5 insertions(+), 59 deletions(-) (limited to 'Source/Samples/LuaxTest/main.cpp') 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 }; //---------------------------------------------------------------------------------------------------------------- -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(); state.PopNamespace(); // Asura + state.PopNamespace(); // Global state.DoString(script); runtime.Close(L); -- cgit v1.1-26-g67d0