From 70b82d1981c0de3c7b77670ff8abcfeb26815142 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 12 Mar 2019 00:39:26 +0800 Subject: *misc --- Source/3rdParty/Luax/luax.h | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'Source/3rdParty/Luax/luax.h') diff --git a/Source/3rdParty/Luax/luax.h b/Source/3rdParty/Luax/luax.h index 68ff9f2..66162a4 100644 --- a/Source/3rdParty/Luax/luax.h +++ b/Source/3rdParty/Luax/luax.h @@ -1,11 +1,8 @@ #ifndef __LUAX_H__ #define __LUAX_H__ -extern "C" { -#include "lua.h" -#include "lualib.h" -#include "lauxlib.h" -} +// 从moai-core中抽离出来 + // include lua.hpp before this #include "luax_runtime.h" #include "luax_state.h" @@ -17,5 +14,38 @@ extern "C" { // * modules // * class // * +/* + +GetClassName +GetClass +New +Extend +GetInterfaceTable + + + +__index +__newIndex +__gc +__mode +__tostring + + + +数据成员不需要允许访问(赋值和得到值),通过函数实现,即__index设置为元表 + +名称空间通过表实现 + +通过upvalue实现调用者的访问,而不需要通过传入self,比如通过BaseClass.Extend("SubClass")访问BaseClass,区分不同的base class, +把BaseClass设为Extend的upvalue,在cfunction通过lua_upvalueindex宏里访问upvalue。 + +之所以能通过.调用函数是因为元表,元表可以给userdata和table作为元表,所以userdata可以调用,但实际上不需要这样。 + +interface table -> member table +member table -> ref table +ref table -> userdata 保存了对每个其他类型的引用和引用计数(用hLuaUserdata作为key),计数是为了debug + +class table 是类型的本体(工厂),有New、Extend、GetClassName方法 +*/ #endif \ No newline at end of file -- cgit v1.1-26-g67d0