summaryrefslogtreecommitdiff
path: root/src/lua51/lobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua51/lobject.h')
-rw-r--r--src/lua51/lobject.h39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/lua51/lobject.h b/src/lua51/lobject.h
index 4e9daee..ead9391 100644
--- a/src/lua51/lobject.h
+++ b/src/lua51/lobject.h
@@ -242,14 +242,14 @@ typedef struct Proto {
CommonHeader;
//c 常量表,能看出来lua保存常量的单元是函数原型,所有代码片段都会被编译为proto
TValue *k; /* constants used by the function */
- //c 函数字节码
+ //c 函数字节码起始点
Instruction *code;
//c 内部函数
struct Proto **p; /* functions defined inside the function */
int *lineinfo; /* map from opcodes to source lines */
//c 局部变量
struct LocVar *locvars; /* information about local variables */
- //c upvalue
+ //c upvalues
TString **upvalues; /* upvalue names */
TString *source; //文件名
int sizeupvalues;
@@ -262,9 +262,9 @@ typedef struct Proto {
int lastlinedefined;
GCObject *gclist;
lu_byte nups; /* number of upvalues */
- lu_byte numparams;
- lu_byte is_vararg;
- lu_byte maxstacksize;
+ lu_byte numparams; //c 参数个数
+ lu_byte is_vararg; //c 是否是可变参数...
+ lu_byte maxstacksize; //c 最大栈大小, 通常200
} Proto;
@@ -286,10 +286,35 @@ typedef struct LocVar {
/*
** Upvalues
*/
-// 判断upvalue是关闭的方式是 uv->v == &uv->u.value
+//c 判断upvalue是关闭的方式是 uv->v == &uv->u.value
+//c upvalue有开闭的概念
+//c 开是指upvalue完全由此方法所有,之前的调用已经结束
+//c 关闭是指upvalue还在之前的栈上
+/*
+* function func()
+* local a = 10;
+* local b = function()
+* a = a + 1
+* print(a)
+* end
+* b() -- 这个是开
+* end
+*
+* function func()
+* local a = 10;
+* local b = function()
+* a = a + 1
+* print(a)
+* end
+* return b
+* end
+*
+* fn = func()
+* fn() -- 这个是关
+*/
typedef struct UpVal {
CommonHeader;
- TValue *v; /* points to stack or to its own value */
+ TValue *v; /* points to stack or to its own value */ //c upvalue的栈地址
union {
TValue value; /* the value (when closed) */
struct { /* double linked list (when open) */