-
Notifications
You must be signed in to change notification settings - Fork 354
Lua 5.2 Changes
viruscamp edited this page Jun 19, 2015
·
2 revisions
- string subtypes different in versions
5.2.0 does not have LUA_TSHRSTR and LUA_TLNGSTR
but 5.2.1 and newer version of 5.2 all have defined these.
/* Variant tags for strings */
#define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */
#define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */
- upval _ENV instead of _G
_ENV is a upval, the top level function has only one upval _ENV, other function's _ENV links to top one by one.
_ENV 是 upval ,顶层函数有且只有一个 upval _ENV ,其他函数的 _ENV 逐层向上指到顶层。
OP_GETGLOBAL --> OP_GETTABUP
OP_SETGLOBAL --> OP_SETTABUP
a --> _ENV.a
- new operators
OP_LOADKX,/* A R(A) := Kst(extra arg) */
OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
- changed operators
- OP_CLOSE,/* A close all upvalues >= R(A) */
* OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A-1) */
- OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */
+ OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */
- OP_TFORLOOP,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */
+ OP_TFORCALL,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
+ OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/
- Proto.upvalues
- Proto.nups
TString** Proto.upvalues --> Upvaldesc* Proto.upvalues
OP_CLOSURE will not be followed by OP_MOVE or OP_GETUPVALUE, use Proto.upvalues.instack and Proto.upvalues.idx
OP_CLOSURE 后面不会再有设置 upval 的 OP_MOVE or OP_GETUPVALUE 了,现在用 Proto.upvalues.instack 和 Proto.upvalues.idx 来取代。
#if LUA_VERSION_NUM == 501
#define luadec_freearray(L, b, n, t) luaM_freearray(L, b, n, t)
#define UPVAL_TYPE TString*
#define NUPS(f) (f->nups)
#define UPVAL_NAME(f, r) (f->upvalues[r])
#endif
#if LUA_VERSION_NUM == 502
#define lua_open() luaL_newstate()
#define luadec_freearray(L, b, n, t) luaM_freearray(L, b, n)
#define UPVAL_TYPE Upvaldesc
#define NUPS(f) (f->sizeupvalues)
#define UPVAL_NAME(f, r) (f->upvalues[r].name)
#endif
- no nil optimizations for locals defined at start of a function
5.1 with nil optimizations
>local a,b,c; local d=3;
[1] loadk 3 0 ; R3 := 3
[2] return 0 1 ; return
5.2 and 5.3 without nil optimizations
>local a,b,c; local d=3;
[1] loadnil 0 2 ; R0 to R2 := nil
[2] loadk 3 0 ; R3 := K0(=3)
[3] return 0 1 ; return