summaryrefslogtreecommitdiff
path: root/Source/3rdParty/Luax/luax_class.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-03-17 20:36:39 +0800
committerchai <chaifix@163.com>2019-03-17 20:36:39 +0800
commit34fe8e795aaeed3a9f50d895d1cadd8f124c9605 (patch)
tree9242101b5d08474bf68aefe1c9ea8bb024a8cfb1 /Source/3rdParty/Luax/luax_class.cpp
parentaf78bbf9f1ea499be92611aa4a63664d79d13b25 (diff)
*luax
Diffstat (limited to 'Source/3rdParty/Luax/luax_class.cpp')
-rw-r--r--Source/3rdParty/Luax/luax_class.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/Source/3rdParty/Luax/luax_class.cpp b/Source/3rdParty/Luax/luax_class.cpp
index 8c94248..155fd28 100644
--- a/Source/3rdParty/Luax/luax_class.cpp
+++ b/Source/3rdParty/Luax/luax_class.cpp
@@ -39,6 +39,30 @@ namespace Luax
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;
}
@@ -64,8 +88,9 @@ namespace Luax
lua_pushvalue(L, classTable);
lua_setmetatable(L, -2);
+ // ҵ캯ᴥmetatable.__index,ݼ̳ҡ
lua_getfield(L, classTable, "Ctor");
- if (!lua_isnil(L, -1))
+ if (state.IsType(-1, LUA_TFUNCTION))
{
// stack:
// -1: Ctor()
@@ -145,13 +170,17 @@ namespace Luax
lua_pushcclosure(L, l_Extend, 1);
lua_setfield(L, -2, "Extend");
- // .base
+ // .__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);