summaryrefslogtreecommitdiff
path: root/Source/Samples/LuaxTest
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Samples/LuaxTest')
-rw-r--r--Source/Samples/LuaxTest/main.cpp64
-rw-r--r--Source/Samples/LuaxTest/script.lua63
2 files changed, 68 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);
diff --git a/Source/Samples/LuaxTest/script.lua b/Source/Samples/LuaxTest/script.lua
new file mode 100644
index 0000000..84bcba9
--- /dev/null
+++ b/Source/Samples/LuaxTest/script.lua
@@ -0,0 +1,63 @@
+string script = R"scriptcode(
+-- start script
+
+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)
+
+
+-- end script
+)scriptcode"; \ No newline at end of file