summaryrefslogtreecommitdiff
path: root/Source/3rdParty/Luax/luax_class.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-03-19 23:06:27 +0800
committerchai <chaifix@163.com>2019-03-19 23:06:27 +0800
commit1497dccd63a84b7ee2b229b1ad9c5c02718f2a78 (patch)
treef8d1bff50da13e126d08c7345653e002e293202d /Source/3rdParty/Luax/luax_class.cpp
parent5e2a973516e0729b225da9de0b03015dc5854ac4 (diff)
*rename
Diffstat (limited to 'Source/3rdParty/Luax/luax_class.cpp')
-rw-r--r--Source/3rdParty/Luax/luax_class.cpp195
1 files changed, 0 insertions, 195 deletions
diff --git a/Source/3rdParty/Luax/luax_class.cpp b/Source/3rdParty/Luax/luax_class.cpp
deleted file mode 100644
index 4c74926..0000000
--- a/Source/3rdParty/Luax/luax_class.cpp
+++ /dev/null
@@ -1,195 +0,0 @@
-#include "luax_class.hpp"
-#include "luax_runtime.h"
-#include "luax_cfunctions.h"
-
-namespace Luax
-{
-
-#ifdef LUAX_ENABLE_PLAIN_CLASS
-
- int LuaxPlainClass::registry(lua_State* L)
- {
- LUAX_STATE(L);
-
- // params:
- // 1: class name
-
- cc8* type = state.GetValue<cc8*>(1, "");
-
- lua_newtable(L); // class table
-
- // GetClassName()
- lua_pushstring(L, type);
- lua_pushcclosure(L, luax_c_getupvalue, 1);
- lua_setfield(L, -2, "GetClassName");
-
- // GetClass()
- lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, luax_c_getupvalue, 1);
- lua_setfield(L, -2, "GetClass");
-
- // New()
- lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, l_New, 1);
- lua_setfield(L, -2, "New");
-
- // Extend()
- lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, l_Extend, 1);
- lua_setfield(L, -2, "Extend");
-
- lua_pushvalue(L, -1); // class table
- lua_setfield(L, -2, "__index");
-
- lua_pushstring(L, type);
- lua_pushcclosure(L, l___tostring, 1);
- lua_setfield(L, -2, "__tostring");
-
- return 1;
- }
-
- int LuaxPlainClass::l___tostring(lua_State* L)
- {
- // upvalues:
- // 1: class name
-
- // params:
- // 1: instance
-
- if (!lua_istable(L, 1))
- {
- return luaL_typerror(L, 1, lua_typename(L, LUA_TTABLE));
- }
-
- cc8* type = lua_tostring(L, lua_upvalueindex(1));
-
- lua_pushfstring(L, "%s: %p", type, lua_topointer(L, 1));
-
- return 1;
- }
-
- ///
- /// NewnԻȡCtorCtorʼʵ
- ///
- int LuaxPlainClass::l_New(lua_State* L)
- {
- LUAX_STATE(L);
-
- // upvalues:
- // 1: class table
-
- // params:
- // n: params
- int n = lua_gettop(L);
-
- int classTable = lua_upvalueindex(1);
-
- lua_newtable(L); // instance table
-
- // instance metatable Ϊ class
- lua_pushvalue(L, classTable);
- lua_setmetatable(L, -2);
-
- // ҵ캯ᴥmetatable.__index,ݼ̳ҡ
- lua_getfield(L, classTable, "Ctor");
- if (state.IsType(-1, LUA_TFUNCTION))
- {
- // stack:
- // -1: Ctor()
- // -2: instance
- // -3~-n-2: params
-
- lua_insert(L, -2 - n);
- // stack:
- // -1: instance
- // -2~-n-1: params
- // -n-2: Ctor()
-
- lua_pushvalue(L, -1);
- // stack:
- // -1: instance
- // -2: instance
- // -3~-n-2: params
- // -n-3: Ctor
-
- lua_insert(L, -3 - n);
- // stack:
- // -1: instance
- // -2~-n-1: params
- // -n-2: Ctor()
- // -n-3: instance
-
- lua_insert(L, -1 - n);
- // stack:
- // -1~-n: params
- // -n-1: instance
- // -n-2: Ctor()
- // -n-3: instance
-
- lua_pcall(L, n + 1, 0, 0);
- }
- else
- {
- state.Pop();
- }
-
- return 1;
- }
-
- int LuaxPlainClass::l_Extend(lua_State* L)
- {
- LUAX_STATE(L);
-
- // upvalues:
- // 1: base class
-
- // params:
- // 1: class name
-
- cc8* type = state.GetValue<cc8*>(1, "");
-
- int baseClass = lua_upvalueindex(1);
-
- lua_newtable(L); // class table
-
- // GetClassName()
- lua_pushstring(L, type);
- lua_pushcclosure(L, luax_c_getupvalue, 1);
- lua_setfield(L, -2, "GetClassName");
-
- // GetClass()
- lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, luax_c_getupvalue, 1);
- lua_setfield(L, -2, "GetClass");
-
- // New()
- lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, l_New, 1);
- lua_setfield(L, -2, "New");
-
- // Extend()
- lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, l_Extend, 1);
- lua_setfield(L, -2, "Extend");
-
- // .__base
- lua_pushvalue(L, baseClass); // base class
- lua_setfield(L, -2, "__base");
-
- lua_pushvalue(L, -1); // class table
- lua_setfield(L, -2, "__index");
-
- lua_pushstring(L, type);
- lua_pushcclosure(L, l___tostring, 1);
- lua_setfield(L, -2, "__tostring");
-
- // classmetatableΪbaseClass
- lua_pushvalue(L, baseClass);
- lua_setmetatable(L, -2);
-
- return 1;
- }
-
-#endif /*LUAX_ENABLE_PLAIN_CLASS*/
-
-} \ No newline at end of file