From 8d036169fe5d6cb1e2ebe1e91622c95956aa6d28 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Tue, 24 Feb 2026 06:36:11 +0000 Subject: [PATCH 01/12] Add support for building on illumos and Solaris --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ecb0da5..dc9cc9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,6 +139,12 @@ impl Build { _ if target.ends_with("bsd") => { config.define("LUA_USE_LINUX", None); } + _ if target.ends_with("illumos") => { + config.define("LUA_USE_POSIX", None); + } + _ if target.ends_with("solaris") => { + config.define("LUA_USE_POSIX", None); + } _ if target.contains("apple-darwin") => { match version { Lua51 => config.define("LUA_USE_LINUX", None), From 8e5cb7b430ba0efbb4e3e8b69e51b7e02348d8bf Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sat, 28 Mar 2026 13:29:55 +0000 Subject: [PATCH 02/12] Bump CI dependencies --- .github/actions/setup-deps/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-deps/action.yml b/.github/actions/setup-deps/action.yml index c213a88..3ba1379 100644 --- a/.github/actions/setup-deps/action.yml +++ b/.github/actions/setup-deps/action.yml @@ -9,10 +9,10 @@ inputs: default: latest wasi_sdk: description: 'wasi-sdk version to install' - default: 29 + default: 32 wasmtime: description: 'wasmtime version to install' - default: v40.0.0 + default: v43.0.0 runs: using: composite From 141aeae63e21df5fce8f25d69c03bcb01af7120c Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sat, 28 Mar 2026 14:00:23 +0000 Subject: [PATCH 03/12] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4308d82..39ad86c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ target/ **/*.rs.bk Cargo.lock + +.vscode/ From c64195236aa2ca498ffba254f3d0b8c4c236cade Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sat, 28 Mar 2026 14:12:31 +0000 Subject: [PATCH 04/12] Expose Lua lib and include dirs --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c97946a..d3ccf84 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -284,6 +284,8 @@ impl Artifacts { for lib in self.libs.iter() { println!("cargo:rustc-link-lib=static:-bundle={lib}"); } + println!("cargo:include={}", self.include_dir.display()); + println!("cargo:lib={}", self.lib_dir.display()); } } From 178af5ab1dd388fd378cb9cb24d65747e08f5a5e Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sat, 28 Mar 2026 14:24:02 +0000 Subject: [PATCH 05/12] v550.1.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 01ca6c4..3942a8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lua-src" -version = "550.0.0" +version = "550.1.0" authors = ["Aleksandr Orlenko "] edition = "2024" repository = "https://github.com/mlua-rs/lua-src-rs" From 2f56d7320009b63ba792ff6557837938e4ad09d1 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sat, 23 May 2026 16:20:12 +0000 Subject: [PATCH 06/12] fix: add DragonFlyBSD target support DragonFly's Rust target triple is `x86_64-unknown-dragonfly` which doesn't end with "bsd", so the existing check missed it. DragonFly is a BSD and uses the same POSIX/Linux-compatible Lua build flags. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d3ccf84..24dc14e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,7 +136,7 @@ impl Build { _ if target.contains("linux") => { config.define("LUA_USE_LINUX", None); } - _ if target.ends_with("bsd") => { + _ if target.ends_with("bsd") || target.contains("dragonfly") => { config.define("LUA_USE_LINUX", None); } _ if target.ends_with("illumos") => { From 85780d1c65f15d6892080f017fbf938a3275e969 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Mon, 25 May 2026 16:46:55 +0100 Subject: [PATCH 07/12] Better NetBSD support Close #18 --- src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 24dc14e..75fa734 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,7 +136,10 @@ impl Build { _ if target.contains("linux") => { config.define("LUA_USE_LINUX", None); } - _ if target.ends_with("bsd") || target.contains("dragonfly") => { + _ if target.ends_with("bsd") + || target.contains("netbsd") + || target.contains("dragonfly") => + { config.define("LUA_USE_LINUX", None); } _ if target.ends_with("illumos") => { From 4518bd02e3e60a0f0908976e44974a0d386e081b Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Tue, 26 May 2026 23:26:40 +0100 Subject: [PATCH 08/12] v550.1.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3942a8f..8219a7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lua-src" -version = "550.1.0" +version = "550.1.1" authors = ["Aleksandr Orlenko "] edition = "2024" repository = "https://github.com/mlua-rs/lua-src-rs" From 1d1a6a267167b291a896e81f49876ad9acc642ac Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 5 Aug 2026 22:11:11 +0100 Subject: [PATCH 09/12] Update Lua to 5.5.1 --- {lua-5.5.0 => lua-5.5.1}/lapi.c | 28 +++++++----- {lua-5.5.0 => lua-5.5.1}/lapi.h | 0 {lua-5.5.0 => lua-5.5.1}/lauxlib.c | 20 +++++++-- {lua-5.5.0 => lua-5.5.1}/lauxlib.h | 6 +-- {lua-5.5.0 => lua-5.5.1}/lbaselib.c | 35 ++++++--------- {lua-5.5.0 => lua-5.5.1}/lcode.c | 19 ++++---- {lua-5.5.0 => lua-5.5.1}/lcode.h | 0 {lua-5.5.0 => lua-5.5.1}/lcorolib.c | 0 {lua-5.5.0 => lua-5.5.1}/lctype.c | 0 {lua-5.5.0 => lua-5.5.1}/lctype.h | 0 {lua-5.5.0 => lua-5.5.1}/ldblib.c | 2 +- {lua-5.5.0 => lua-5.5.1}/ldebug.c | 4 +- {lua-5.5.0 => lua-5.5.1}/ldebug.h | 0 {lua-5.5.0 => lua-5.5.1}/ldo.c | 68 ++++++++++++++++++++--------- {lua-5.5.0 => lua-5.5.1}/ldo.h | 2 +- {lua-5.5.0 => lua-5.5.1}/ldump.c | 0 {lua-5.5.0 => lua-5.5.1}/lfunc.c | 0 {lua-5.5.0 => lua-5.5.1}/lfunc.h | 0 {lua-5.5.0 => lua-5.5.1}/lgc.c | 6 +-- {lua-5.5.0 => lua-5.5.1}/lgc.h | 0 {lua-5.5.0 => lua-5.5.1}/linit.c | 0 {lua-5.5.0 => lua-5.5.1}/liolib.c | 1 - {lua-5.5.0 => lua-5.5.1}/ljumptab.h | 0 {lua-5.5.0 => lua-5.5.1}/llex.c | 2 +- {lua-5.5.0 => lua-5.5.1}/llex.h | 0 {lua-5.5.0 => lua-5.5.1}/llimits.h | 12 ++--- {lua-5.5.0 => lua-5.5.1}/lmathlib.c | 0 {lua-5.5.0 => lua-5.5.1}/lmem.c | 0 {lua-5.5.0 => lua-5.5.1}/lmem.h | 0 {lua-5.5.0 => lua-5.5.1}/loadlib.c | 2 +- {lua-5.5.0 => lua-5.5.1}/lobject.c | 0 {lua-5.5.0 => lua-5.5.1}/lobject.h | 3 +- {lua-5.5.0 => lua-5.5.1}/lopcodes.c | 25 ++++------- {lua-5.5.0 => lua-5.5.1}/lopcodes.h | 15 ++++--- {lua-5.5.0 => lua-5.5.1}/lopnames.h | 0 {lua-5.5.0 => lua-5.5.1}/loslib.c | 1 - {lua-5.5.0 => lua-5.5.1}/lparser.c | 28 ++++++------ {lua-5.5.0 => lua-5.5.1}/lparser.h | 5 ++- {lua-5.5.0 => lua-5.5.1}/lprefix.h | 0 {lua-5.5.0 => lua-5.5.1}/lstate.c | 21 +++++---- {lua-5.5.0 => lua-5.5.1}/lstate.h | 42 +++++++++--------- {lua-5.5.0 => lua-5.5.1}/lstring.c | 0 {lua-5.5.0 => lua-5.5.1}/lstring.h | 0 {lua-5.5.0 => lua-5.5.1}/lstrlib.c | 18 +++++--- {lua-5.5.0 => lua-5.5.1}/ltable.c | 16 +++---- {lua-5.5.0 => lua-5.5.1}/ltable.h | 0 {lua-5.5.0 => lua-5.5.1}/ltablib.c | 12 ++--- {lua-5.5.0 => lua-5.5.1}/ltm.c | 10 ++--- {lua-5.5.0 => lua-5.5.1}/ltm.h | 2 +- {lua-5.5.0 => lua-5.5.1}/lua.h | 6 +-- {lua-5.5.0 => lua-5.5.1}/luaconf.h | 39 +++++++++++------ {lua-5.5.0 => lua-5.5.1}/lualib.h | 0 {lua-5.5.0 => lua-5.5.1}/lundump.c | 13 +++--- {lua-5.5.0 => lua-5.5.1}/lundump.h | 4 +- {lua-5.5.0 => lua-5.5.1}/lutf8lib.c | 7 ++- {lua-5.5.0 => lua-5.5.1}/lvm.c | 28 +++++++----- {lua-5.5.0 => lua-5.5.1}/lvm.h | 0 {lua-5.5.0 => lua-5.5.1}/lzio.c | 0 {lua-5.5.0 => lua-5.5.1}/lzio.h | 0 src/lib.rs | 2 +- 60 files changed, 284 insertions(+), 220 deletions(-) rename {lua-5.5.0 => lua-5.5.1}/lapi.c (98%) rename {lua-5.5.0 => lua-5.5.1}/lapi.h (100%) rename {lua-5.5.0 => lua-5.5.1}/lauxlib.c (98%) rename {lua-5.5.0 => lua-5.5.1}/lauxlib.h (97%) rename {lua-5.5.0 => lua-5.5.1}/lbaselib.c (94%) rename {lua-5.5.0 => lua-5.5.1}/lcode.c (99%) rename {lua-5.5.0 => lua-5.5.1}/lcode.h (100%) rename {lua-5.5.0 => lua-5.5.1}/lcorolib.c (100%) rename {lua-5.5.0 => lua-5.5.1}/lctype.c (100%) rename {lua-5.5.0 => lua-5.5.1}/lctype.h (100%) rename {lua-5.5.0 => lua-5.5.1}/ldblib.c (99%) rename {lua-5.5.0 => lua-5.5.1}/ldebug.c (99%) rename {lua-5.5.0 => lua-5.5.1}/ldebug.h (100%) rename {lua-5.5.0 => lua-5.5.1}/ldo.c (94%) rename {lua-5.5.0 => lua-5.5.1}/ldo.h (97%) rename {lua-5.5.0 => lua-5.5.1}/ldump.c (100%) rename {lua-5.5.0 => lua-5.5.1}/lfunc.c (100%) rename {lua-5.5.0 => lua-5.5.1}/lfunc.h (100%) rename {lua-5.5.0 => lua-5.5.1}/lgc.c (99%) rename {lua-5.5.0 => lua-5.5.1}/lgc.h (100%) rename {lua-5.5.0 => lua-5.5.1}/linit.c (100%) rename {lua-5.5.0 => lua-5.5.1}/liolib.c (99%) rename {lua-5.5.0 => lua-5.5.1}/ljumptab.h (100%) rename {lua-5.5.0 => lua-5.5.1}/llex.c (99%) rename {lua-5.5.0 => lua-5.5.1}/llex.h (100%) rename {lua-5.5.0 => lua-5.5.1}/llimits.h (96%) rename {lua-5.5.0 => lua-5.5.1}/lmathlib.c (100%) rename {lua-5.5.0 => lua-5.5.1}/lmem.c (100%) rename {lua-5.5.0 => lua-5.5.1}/lmem.h (100%) rename {lua-5.5.0 => lua-5.5.1}/loadlib.c (99%) rename {lua-5.5.0 => lua-5.5.1}/lobject.c (100%) rename {lua-5.5.0 => lua-5.5.1}/lobject.h (99%) rename {lua-5.5.0 => lua-5.5.1}/lopcodes.c (89%) rename {lua-5.5.0 => lua-5.5.1}/lopcodes.h (97%) rename {lua-5.5.0 => lua-5.5.1}/lopnames.h (100%) rename {lua-5.5.0 => lua-5.5.1}/loslib.c (99%) rename {lua-5.5.0 => lua-5.5.1}/lparser.c (99%) rename {lua-5.5.0 => lua-5.5.1}/lparser.h (97%) rename {lua-5.5.0 => lua-5.5.1}/lprefix.h (100%) rename {lua-5.5.0 => lua-5.5.1}/lstate.c (95%) rename {lua-5.5.0 => lua-5.5.1}/lstate.h (92%) rename {lua-5.5.0 => lua-5.5.1}/lstring.c (100%) rename {lua-5.5.0 => lua-5.5.1}/lstring.h (100%) rename {lua-5.5.0 => lua-5.5.1}/lstrlib.c (99%) rename {lua-5.5.0 => lua-5.5.1}/ltable.c (99%) rename {lua-5.5.0 => lua-5.5.1}/ltable.h (100%) rename {lua-5.5.0 => lua-5.5.1}/ltablib.c (97%) rename {lua-5.5.0 => lua-5.5.1}/ltm.c (97%) rename {lua-5.5.0 => lua-5.5.1}/ltm.h (97%) rename {lua-5.5.0 => lua-5.5.1}/lua.h (99%) rename {lua-5.5.0 => lua-5.5.1}/luaconf.h (95%) rename {lua-5.5.0 => lua-5.5.1}/lualib.h (100%) rename {lua-5.5.0 => lua-5.5.1}/lundump.c (97%) rename {lua-5.5.0 => lua-5.5.1}/lundump.h (85%) rename {lua-5.5.0 => lua-5.5.1}/lutf8lib.c (97%) rename {lua-5.5.0 => lua-5.5.1}/lvm.c (98%) rename {lua-5.5.0 => lua-5.5.1}/lvm.h (100%) rename {lua-5.5.0 => lua-5.5.1}/lzio.c (100%) rename {lua-5.5.0 => lua-5.5.1}/lzio.h (100%) diff --git a/lua-5.5.0/lapi.c b/lua-5.5.1/lapi.c similarity index 98% rename from lua-5.5.0/lapi.c rename to lua-5.5.1/lapi.c index 27fa524..8bc2ddd 100644 --- a/lua-5.5.0/lapi.c +++ b/lua-5.5.1/lapi.c @@ -187,7 +187,7 @@ LUA_API void lua_settop (lua_State *L, int idx) { api_check(L, idx <= ci->top.p - (func + 1), "new top too large"); diff = ((func + 1) + idx) - L->top.p; for (; diff > 0; diff--) - setnilvalue(s2v(L->top.p++)); /* clear new slots */ + setnilvalue2s(L->top.p++); /* clear new slots */ } else { api_check(L, -(idx+1) <= (L->top.p - (func + 1)), "invalid new top"); @@ -210,7 +210,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) { api_check(L, (L->ci->callstatus & CIST_TBC) && (L->tbclist.p == level), "no variable to close at given level"); level = luaF_close(L, level, CLOSEKTOP, 0); - setnilvalue(s2v(level)); + setnilvalue2s(level); lua_unlock(L); } @@ -366,7 +366,7 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { } -LUA_API unsigned (lua_numbertocstring) (lua_State *L, int idx, char *buff) { +LUA_API unsigned lua_numbertocstring (lua_State *L, int idx, char *buff) { const TValue *o = index2value(L, idx); if (ttisnumber(o)) { unsigned len = luaO_tostringbuff(o, buff); @@ -513,7 +513,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { LUA_API void lua_pushnil (lua_State *L) { lua_lock(L); - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); api_incr_top(L); lua_unlock(L); } @@ -570,7 +570,7 @@ LUA_API const char *lua_pushexternalstring (lua_State *L, LUA_API const char *lua_pushstring (lua_State *L, const char *s) { lua_lock(L); if (s == NULL) - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); else { TString *ts; ts = luaS_new(L, s); @@ -743,7 +743,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { static int finishrawget (lua_State *L, lu_byte tag) { if (tagisempty(tag)) /* avoid copying empty items to the stack */ - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); api_incr_top(L); lua_unlock(L); return novariant(tag); @@ -836,7 +836,7 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) { o = index2value(L, idx); api_check(L, ttisfulluserdata(o), "full userdata expected"); if (n <= 0 || n > uvalue(o)->nuvalue) { - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); t = LUA_TNONE; } else { @@ -1122,6 +1122,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, ZIO z; TStatus status; lua_lock(L); + luaC_checkGC(L); if (!chunkname) chunkname = "?"; luaZ_init(L, &z, reader, data); status = luaD_protectedparser(L, &z, chunkname, mode); @@ -1201,11 +1202,16 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { case LUA_GCSTEP: { lu_byte oldstp = g->gcstp; l_mem n = cast(l_mem, va_arg(argp, size_t)); + l_mem newdebt; int work = 0; /* true if GC did some work */ g->gcstp = 0; /* allow GC to run (other bits must be zero here) */ if (n <= 0) - n = g->GCdebt; /* force to run one basic step */ - luaE_setdebt(g, g->GCdebt - n); + newdebt = 0; /* force to run one basic step */ + else if (g->GCdebt >= n - MAX_LMEM) /* no overflow? */ + newdebt = g->GCdebt - n; + else /* overflow */ + newdebt = -MAX_LMEM; /* set debt to mininum value */ + luaE_setdebt(g, newdebt); luaC_condGC(L, (void)0, work = 1); if (work && g->gcstate == GCSpause) /* end of cycle? */ res = 1; /* signal it */ @@ -1293,8 +1299,8 @@ LUA_API void lua_toclose (lua_State *L, int idx) { LUA_API void lua_concat (lua_State *L, int n) { lua_lock(L); - api_checknelems(L, n); if (n > 0) { + api_checkpop(L, n); luaV_concat(L, n); luaC_checkGC(L); } @@ -1412,7 +1418,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { TValue *fi; lua_lock(L); fi = index2value(L, funcindex); - api_checknelems(L, 1); + api_checkpop(L, 1); name = aux_upvalue(fi, n, &val, &owner); if (name) { L->top.p--; diff --git a/lua-5.5.0/lapi.h b/lua-5.5.1/lapi.h similarity index 100% rename from lua-5.5.0/lapi.h rename to lua-5.5.1/lapi.h diff --git a/lua-5.5.0/lauxlib.c b/lua-5.5.1/lauxlib.c similarity index 98% rename from lua-5.5.0/lauxlib.c rename to lua-5.5.1/lauxlib.c index 4b0b462..5351f31 100644 --- a/lua-5.5.0/lauxlib.c +++ b/lua-5.5.1/lauxlib.c @@ -513,12 +513,25 @@ static const luaL_Reg boxmt[] = { /* box metamethods */ }; +/* +** Get/create metatable (MT) for boxes +*/ +static void getBoxMT (lua_State *L) { + const char *BOXMT = "_UBOX*"; /* key for the metatable */ + if (luaL_getmetatable(L, BOXMT) == LUA_TNIL) { /* MT not created yet? */ + luaL_newlibtable(L, boxmt); /* create it */ + luaL_setfuncs(L, boxmt, 0); /* initialize it */ + lua_copy(L, -1, -2); /* change stack from nil,MT to MT,MT */ + lua_setfield(L, LUA_REGISTRYINDEX, BOXMT); /* store MT in the registry */ + } +} + + static void newbox (lua_State *L) { UBox *box = (UBox *)lua_newuserdatauv(L, sizeof(UBox), 0); box->box = NULL; box->bsize = 0; - if (luaL_newmetatable(L, "_UBOX*")) /* creating metatable? */ - luaL_setfuncs(L, boxmt, 0); /* set its metamethods */ + getBoxMT(L); lua_setmetatable(L, -2); } @@ -874,7 +887,7 @@ LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size, LUALIB_API int luaL_loadstring (lua_State *L, const char *s) { - return luaL_loadbuffer(L, s, strlen(s), s); + return luaL_loadbufferx(L, s, strlen(s), s, "t"); } /* }====================================================== */ @@ -1199,4 +1212,3 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) { luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)v); } - diff --git a/lua-5.5.0/lauxlib.h b/lua-5.5.1/lauxlib.h similarity index 97% rename from lua-5.5.0/lauxlib.h rename to lua-5.5.1/lauxlib.h index 7f1d3ca..2d01536 100644 --- a/lua-5.5.0/lauxlib.h +++ b/lua-5.5.1/lauxlib.h @@ -81,8 +81,8 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def, LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); LUALIB_API int (luaL_execresult) (lua_State *L, int stat); -LUALIB_API void *luaL_alloc (void *ud, void *ptr, size_t osize, - size_t nsize); +LUALIB_API void *(luaL_alloc) (void *ud, void *ptr, size_t osize, + size_t nsize); /* predefined references */ @@ -103,7 +103,7 @@ LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); LUALIB_API lua_State *(luaL_newstate) (void); -LUALIB_API unsigned luaL_makeseed (lua_State *L); +LUALIB_API unsigned (luaL_makeseed) (lua_State *L); LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); diff --git a/lua-5.5.0/lbaselib.c b/lua-5.5.1/lbaselib.c similarity index 94% rename from lua-5.5.0/lbaselib.c rename to lua-5.5.1/lbaselib.c index 891bb90..3962ea5 100644 --- a/lua-5.5.0/lbaselib.c +++ b/lua-5.5.1/lbaselib.c @@ -340,9 +340,11 @@ static int load_aux (lua_State *L, int status, int envidx) { static const char *getMode (lua_State *L, int idx) { - const char *mode = luaL_optstring(L, idx, "bt"); - if (strchr(mode, 'B') != NULL) /* Lua code cannot use fixed buffers */ + const char *mode = luaL_optstring(L, idx, NULL); + if (mode != NULL && strchr(mode, 'B') != NULL) { + /* Lua code cannot use fixed buffers */ luaL_argerror(L, idx, "invalid mode"); + } return mode; } @@ -364,33 +366,24 @@ static int luaB_loadfile (lua_State *L) { /* -** reserved slot, above all arguments, to hold a copy of the returned -** string to avoid it being collected while parsed. 'load' has four -** optional arguments (chunk, source name, mode, and environment). -*/ -#define RESERVEDSLOT 5 - - -/* -** Reader for generic 'load' function: 'lua_load' uses the -** stack for internal stuff, so the reader cannot change the -** stack top. Instead, it keeps its resulting string in a -** reserved slot inside the stack. +** Reader for generic 'load' function. */ static const char *generic_reader (lua_State *L, void *ud, size_t *size) { - (void)(ud); /* not used */ + int *firstcall = cast(int *, ud); luaL_checkstack(L, 2, "too many nested functions"); + if (*firstcall) + *firstcall = 0; + else + lua_pop(L, 1); /* remove previous result */ lua_pushvalue(L, 1); /* get function */ lua_call(L, 0, 1); /* call it */ if (lua_isnil(L, -1)) { - lua_pop(L, 1); /* pop result */ *size = 0; return NULL; } else if (l_unlikely(!lua_isstring(L, -1))) luaL_error(L, "reader function must return a string"); - lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */ - return lua_tolstring(L, RESERVEDSLOT, size); + return lua_tolstring(L, -1, size); } @@ -405,10 +398,10 @@ static int luaB_load (lua_State *L) { status = luaL_loadbufferx(L, s, l, chunkname, mode); } else { /* loading from a reader function */ + int firstcall = 1; /* userdata for generic_reader */ const char *chunkname = luaL_optstring(L, 2, "=(load)"); luaL_checktype(L, 1, LUA_TFUNCTION); - lua_settop(L, RESERVEDSLOT); /* create reserved slot */ - status = lua_load(L, generic_reader, NULL, chunkname, mode); + status = lua_load(L, generic_reader, &firstcall, chunkname, mode); } return load_aux(L, status, env); } @@ -425,7 +418,7 @@ static int dofilecont (lua_State *L, int d1, lua_KContext d2) { static int luaB_dofile (lua_State *L) { const char *fname = luaL_optstring(L, 1, NULL); lua_settop(L, 1); - if (l_unlikely(luaL_loadfile(L, fname) != LUA_OK)) + if (l_unlikely(luaL_loadfilex(L, fname, "bt") != LUA_OK)) return lua_error(L); lua_callk(L, 0, LUA_MULTRET, 0, dofilecont); return dofilecont(L, 0, 0); diff --git a/lua-5.5.0/lcode.c b/lua-5.5.1/lcode.c similarity index 99% rename from lua-5.5.0/lcode.c rename to lua-5.5.1/lcode.c index 4caa804..8b61d5d 100644 --- a/lua-5.5.0/lcode.c +++ b/lua-5.5.1/lcode.c @@ -663,11 +663,11 @@ static int boolT (FuncState *fs) { ** Add nil to list of constants and return its index. */ static int nilK (FuncState *fs) { - TValue k, v; - setnilvalue(&v); + lua_State *L = fs->ls->L; + TValue k; /* cannot use nil as key; instead use table itself */ - sethvalue(fs->ls->L, &k, fs->kcache); - return k2proto(fs, &k, &v); + sethvalue(L, &k, fs->kcache); + return k2proto(fs, &k, &G(L)->nilvalue); } @@ -827,7 +827,7 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { } /* FALLTHROUGH */ case VLOCAL: { /* already in a register */ int temp = e->u.var.ridx; - e->u.info = temp; /* (can't do a direct assignment; values overlap) */ + e->u.info = temp; /* (avoid a direct assignment; values overlap) */ e->k = VNONRELOC; /* becomes a non-relocatable value */ break; } @@ -1365,7 +1365,7 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { luaK_exp2anyreg(fs, t); /* put it in a register */ if (t->k == VUPVAL) { lu_byte temp = cast_byte(t->u.info); /* upvalue index */ - t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */ + t->u.ind.t = temp; /* (avoid a direct assignment; values overlap) */ lua_assert(isKstr(fs, k)); fillidxk(t, k->u.info, VINDEXUP); /* literal short string */ } @@ -1373,12 +1373,13 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { int kreg = luaK_exp2anyreg(fs, k); /* put key in some register */ lu_byte vreg = cast_byte(t->u.var.ridx); /* register with vararg param. */ lua_assert(vreg == fs->f->numparams); - t->u.ind.t = vreg; /* (avoid a direct assignment; values may overlap) */ + t->u.ind.t = vreg; /* (avoid a direct assignment; values may overlap?) */ fillidxk(t, kreg, VVARGIND); /* 't' represents 'vararg[k]' */ } else { /* register index of the table */ - t->u.ind.t = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info); + lu_byte temp = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info); + t->u.ind.t = temp; /* (avoid a direct assignment; values may overlap?) */ if (isKstr(fs, k)) fillidxk(t, k->u.info, VINDEXSTR); /* literal short string */ else if (isCint(k)) /* int. constant in proper range? */ @@ -1933,8 +1934,6 @@ void luaK_finish (FuncState *fs) { p->flag &= cast_byte(~PF_VAHID); /* then it will not use hidden args. */ for (i = 0; i < fs->pc; i++) { Instruction *pc = &p->code[i]; - /* avoid "not used" warnings when assert is off (for 'onelua.c') */ - (void)luaP_isOT; (void)luaP_isIT; lua_assert(i == 0 || luaP_isOT(*(pc - 1)) == luaP_isIT(*pc)); switch (GET_OPCODE(*pc)) { case OP_RETURN0: case OP_RETURN1: { diff --git a/lua-5.5.0/lcode.h b/lua-5.5.1/lcode.h similarity index 100% rename from lua-5.5.0/lcode.h rename to lua-5.5.1/lcode.h diff --git a/lua-5.5.0/lcorolib.c b/lua-5.5.1/lcorolib.c similarity index 100% rename from lua-5.5.0/lcorolib.c rename to lua-5.5.1/lcorolib.c diff --git a/lua-5.5.0/lctype.c b/lua-5.5.1/lctype.c similarity index 100% rename from lua-5.5.0/lctype.c rename to lua-5.5.1/lctype.c diff --git a/lua-5.5.0/lctype.h b/lua-5.5.1/lctype.h similarity index 100% rename from lua-5.5.0/lctype.h rename to lua-5.5.1/lctype.h diff --git a/lua-5.5.0/ldblib.c b/lua-5.5.1/ldblib.c similarity index 99% rename from lua-5.5.0/ldblib.c rename to lua-5.5.1/ldblib.c index c7b7481..051327c 100644 --- a/lua-5.5.0/ldblib.c +++ b/lua-5.5.1/ldblib.c @@ -427,7 +427,7 @@ static int db_debug (lua_State *L) { if (fgets(buffer, sizeof(buffer), stdin) == NULL || strcmp(buffer, "cont\n") == 0) return 0; - if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || + if (luaL_loadbufferx(L, buffer, strlen(buffer), "=(debug command)", "t") || lua_pcall(L, 0, 0, 0)) lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL)); lua_settop(L, 0); /* remove eventual returns */ diff --git a/lua-5.5.0/ldebug.c b/lua-5.5.1/ldebug.c similarity index 99% rename from lua-5.5.0/ldebug.c rename to lua-5.5.1/ldebug.c index 8df5f5f..5293ccb 100644 --- a/lua-5.5.0/ldebug.c +++ b/lua-5.5.1/ldebug.c @@ -291,7 +291,7 @@ static int nextline (const Proto *p, int currentline, int pc) { static void collectvalidlines (lua_State *L, Closure *f) { if (!LuaClosure(f)) { - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); api_incr_top(L); } else { @@ -580,7 +580,7 @@ static const char *getobjname (const Proto *p, int lastpc, int reg, kname(p, k, name); return isEnv(p, lastpc, i, 1); } - case OP_GETTABLE: { + case OP_GETTABLE: case OP_GETVARG: { int k = GETARG_C(i); /* key index */ rname(p, lastpc, k, name); return isEnv(p, lastpc, i, 0); diff --git a/lua-5.5.0/ldebug.h b/lua-5.5.1/ldebug.h similarity index 100% rename from lua-5.5.0/ldebug.h rename to lua-5.5.1/ldebug.h diff --git a/lua-5.5.0/ldo.c b/lua-5.5.1/ldo.c similarity index 94% rename from lua-5.5.0/ldo.c rename to lua-5.5.1/ldo.c index 6d0184e..fe8bf20 100644 --- a/lua-5.5.0/ldo.c +++ b/lua-5.5.1/ldo.c @@ -221,13 +221,21 @@ l_noret luaD_errerr (lua_State *L) { /* -** Check whether stack has enough space to run a simple function (such -** as a finalizer): At least BASIC_STACK_SIZE in the Lua stack and -** 2 slots in the C stack. +** Check whether stacks have enough space to run a simple function (such +** as a finalizer): At least BASIC_STACK_SIZE in the Lua stack, two +** available CallInfos, and two "slots" in the C stack. */ int luaD_checkminstack (lua_State *L) { - return ((stacksize(L) < MAXSTACK - BASIC_STACK_SIZE) && - (getCcalls(L) < LUAI_MAXCCALLS - 2)); + if (getCcalls(L) >= LUAI_MAXCCALLS - 2) + return 0; /* not enough C-stack slots */ + if (L->ci->next == NULL && luaE_extendCI(L, 0) == NULL) + return 0; /* unable to allocate first ci */ + if (L->ci->next->next == NULL && luaE_extendCI(L, 0) == NULL) + return 0; /* unable to allocate second ci */ + if (L->stack_last.p - L->top.p >= BASIC_STACK_SIZE) + return 1; /* enough (BASIC_STACK_SIZE) free slots in the Lua stack */ + else /* try to grow stack to a size with enough free slots */ + return luaD_growstack(L, BASIC_STACK_SIZE, 0); } @@ -341,7 +349,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { correctstack(L, oldstack); /* change offsets back to pointers */ L->stack_last.p = L->stack.p + newsize; for (i = oldsize + EXTRA_STACK; i < newsize + EXTRA_STACK; i++) - setnilvalue(s2v(newstack + i)); /* erase new segment */ + setnilvalue2s(newstack + i); /* erase new segment */ return 1; } @@ -422,12 +430,6 @@ void luaD_shrinkstack (lua_State *L) { luaE_shrinkCI(L); /* shrink CI list */ } - -void luaD_inctop (lua_State *L) { - L->top.p++; - luaD_checkstack(L, 1); -} - /* }================================================================== */ @@ -546,7 +548,7 @@ l_sinline void genmoveresults (lua_State *L, StkId res, int nres, for (i = 0; i < nres; i++) /* move all results to correct place */ setobjs2s(L, res + i, firstresult + i); for (; i < wanted; i++) /* complete wanted number of results */ - setnilvalue(s2v(res + i)); + setnilvalue2s(res + i); L->top.p = res + wanted; /* top points after the last result */ } @@ -566,7 +568,7 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, return; case 1 + 1: /* one value needed */ if (nres == 0) /* no results? */ - setnilvalue(s2v(res)); /* adjust with nil */ + setnilvalue2s(res); /* adjust with nil */ else /* at least one result */ setobjs2s(L, res, L->top.p - nres); /* move it to proper place */ L->top.p = res + 1; @@ -616,7 +618,7 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { -#define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L)) +#define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L, 1)) /* @@ -686,7 +688,7 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, setobjs2s(L, ci->func.p + i, func + i); func = ci->func.p; /* moved-down function */ for (; narg1 <= nfixparams; narg1++) - setnilvalue(s2v(func + narg1)); /* complete missing arguments */ + setnilvalue2s(func + narg1); /* complete missing arguments */ ci->top.p = func + 1 + fsize; /* top for new function */ lua_assert(ci->top.p <= L->stack_last.p); ci->u.l.savedpc = p->code; /* starting point */ @@ -733,7 +735,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { L->ci = ci = prepCallInfo(L, func, status, func + 1 + fsize); ci->u.l.savedpc = p->code; /* starting point */ for (; narg < nfixparams; narg++) - setnilvalue(s2v(L->top.p++)); /* complete missing arguments */ + setnilvalue2s(L->top.p++); /* complete missing arguments */ lua_assert(ci->top.p <= L->stack_last.p); return ci; } @@ -1120,28 +1122,54 @@ static void checkmode (lua_State *L, const char *mode, const char *x) { } +/* +** Before the first call to the reader function, Lua reserves a slot +** with a table for anchoring stuff. +*/ static void f_parser (lua_State *L, void *ud) { LClosure *cl; struct SParser *p = cast(struct SParser *, ud); const char *mode = p->mode ? p->mode : "bt"; - int c = zgetc(p->z); /* read first character */ + int c; + Table *anchor; + ptrdiff_t otop = savestack(L, L->top.p); /* original top */ + luaD_checkstack(L, 2); + anchor = luaH_new(L); /* create the anchor table */ + sethvalue2s(L, L->top.p++, anchor); /* anchor the anchor table */ + c = zgetc(p->z); /* read first character */ if (c == LUA_SIGNATURE[0]) { int fixed = 0; if (strchr(mode, 'B') != NULL) fixed = 1; else checkmode(L, mode, "binary"); - cl = luaU_undump(L, p->z, p->name, fixed); + cl = luaU_undump(L, p->z, anchor, p->name, fixed); } else { checkmode(L, mode, "text"); - cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); + cl = luaY_parser(L, p->z, anchor, &p->buff, &p->dyd, p->name, c); } + L->top.p = restorestack(L, otop); /* restore stack */ + setclLvalue2s(L, L->top.p++, cl); /* push closure */ lua_assert(cl->nupvalues == cl->p->sizeupvalues); luaF_initupvals(L, cl); } +/* +** Anchor an object in a table in the stack. First, anchor the object +** temporarily in the stack, as luaH_set may call an emergency GC. +** Then, add it in the table with itself as its key. +*/ +void luaD_anchorobj (lua_State *L, Table *anchor, GCObject *obj) { + setgcovalue(L, s2v(L->top.p++), obj); /* temporary anchor in the stack */ + luaH_set(L, anchor, s2v(L->top.p - 1), s2v(L->top.p - 1)); + /* Because this is a new key, luaH_set will call the GC barrier, so + we don't need to call the barrier again here */ + L->top.p--; +} + + TStatus luaD_protectedparser (lua_State *L, ZIO *z, const char *name, const char *mode) { struct SParser p; diff --git a/lua-5.5.0/ldo.h b/lua-5.5.1/ldo.h similarity index 97% rename from lua-5.5.0/ldo.h rename to lua-5.5.1/ldo.h index b647295..85a00e3 100644 --- a/lua-5.5.0/ldo.h +++ b/lua-5.5.1/ldo.h @@ -88,8 +88,8 @@ LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres); LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror); LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror); LUAI_FUNC void luaD_shrinkstack (lua_State *L); -LUAI_FUNC void luaD_inctop (lua_State *L); LUAI_FUNC int luaD_checkminstack (lua_State *L); +LUAI_FUNC void luaD_anchorobj (lua_State *L, Table *anchor, GCObject *obj); LUAI_FUNC l_noret luaD_throw (lua_State *L, TStatus errcode); LUAI_FUNC l_noret luaD_throwbaselevel (lua_State *L, TStatus errcode); diff --git a/lua-5.5.0/ldump.c b/lua-5.5.1/ldump.c similarity index 100% rename from lua-5.5.0/ldump.c rename to lua-5.5.1/ldump.c diff --git a/lua-5.5.0/lfunc.c b/lua-5.5.1/lfunc.c similarity index 100% rename from lua-5.5.0/lfunc.c rename to lua-5.5.1/lfunc.c diff --git a/lua-5.5.0/lfunc.h b/lua-5.5.1/lfunc.h similarity index 100% rename from lua-5.5.0/lfunc.h rename to lua-5.5.1/lfunc.h diff --git a/lua-5.5.0/lgc.c b/lua-5.5.1/lgc.c similarity index 99% rename from lua-5.5.0/lgc.c rename to lua-5.5.1/lgc.c index c64d74b..a463e41 100644 --- a/lua-5.5.0/lgc.c +++ b/lua-5.5.1/lgc.c @@ -709,7 +709,7 @@ static l_mem traversethread (global_State *g, lua_State *th) { if (!g->gcemergency) luaD_shrinkstack(th); /* do not change stack in emergency cycle */ for (o = th->top.p; o < th->stack_last.p + EXTRA_STACK; o++) - setnilvalue(s2v(o)); /* clear dead stack slice */ + setnilvalue2s(o); /* clear dead stack slice */ /* 'remarkupvals' may have removed thread from 'twups' list */ if (!isintwups(th) && th->openupval != NULL) { th->twups = g->twups; /* link it back to the list */ @@ -1293,7 +1293,7 @@ static void finishgencycle (lua_State *L, global_State *g) { correctgraylists(g); checkSizes(L, g); g->gcstate = GCSpropagate; /* skip restart */ - if (!g->gcemergency && luaD_checkminstack(L)) + if (g->tobefnz != NULL && !g->gcemergency && luaD_checkminstack(L)) callallpendingfinalizers(L); } @@ -1672,7 +1672,7 @@ static l_mem singlestep (lua_State *L, int fast) { GCTM(L); /* call one finalizer */ stepresult = CWUFIN; } - else { /* no more finalizers or emergency mode or no enough stack + else { /* no more finalizers or emergency mode or not enough stack to run finalizers */ g->gcstate = GCSpause; /* finish collection */ stepresult = step2pause; diff --git a/lua-5.5.0/lgc.h b/lua-5.5.1/lgc.h similarity index 100% rename from lua-5.5.0/lgc.h rename to lua-5.5.1/lgc.h diff --git a/lua-5.5.0/linit.c b/lua-5.5.1/linit.c similarity index 100% rename from lua-5.5.0/linit.c rename to lua-5.5.1/linit.c diff --git a/lua-5.5.0/liolib.c b/lua-5.5.1/liolib.c similarity index 99% rename from lua-5.5.0/liolib.c rename to lua-5.5.1/liolib.c index 29e455d..5d46f5d 100644 --- a/lua-5.5.0/liolib.c +++ b/lua-5.5.1/liolib.c @@ -848,4 +848,3 @@ LUAMOD_API int luaopen_io (lua_State *L) { createstdfile(L, stderr, NULL, "stderr"); return 1; } - diff --git a/lua-5.5.0/ljumptab.h b/lua-5.5.1/ljumptab.h similarity index 100% rename from lua-5.5.0/ljumptab.h rename to lua-5.5.1/ljumptab.h diff --git a/lua-5.5.0/llex.c b/lua-5.5.1/llex.c similarity index 99% rename from lua-5.5.0/llex.c rename to lua-5.5.1/llex.c index f8bb3ea..7cd9fca 100644 --- a/lua-5.5.0/llex.c +++ b/lua-5.5.1/llex.c @@ -188,7 +188,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, so they cannot be collected */ ls->envn = luaS_newliteral(L, LUA_ENV); /* get env string */ ls->brkn = luaS_newliteral(L, "break"); /* get "break" string */ -#if defined(LUA_COMPAT_GLOBAL) +#if LUA_COMPAT_GLOBAL /* compatibility mode: "global" is not a reserved word */ ls->glbn = luaS_newliteral(L, "global"); /* get "global" string */ ls->glbn->extra = 0; /* mark it as not reserved */ diff --git a/lua-5.5.0/llex.h b/lua-5.5.1/llex.h similarity index 100% rename from lua-5.5.0/llex.h rename to lua-5.5.1/llex.h diff --git a/lua-5.5.0/llimits.h b/lua-5.5.1/llimits.h similarity index 96% rename from lua-5.5.0/llimits.h rename to lua-5.5.1/llimits.h index fc5cb27..3f03725 100644 --- a/lua-5.5.0/llimits.h +++ b/lua-5.5.1/llimits.h @@ -234,12 +234,12 @@ typedef unsigned long l_uint32; /* floor division (defined as 'floor(a/b)') */ #if !defined(luai_numidiv) -#define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b))) +#define luai_numidiv(L,a,b) l_floor(luai_numdiv(L,a,b)) #endif /* float division */ #if !defined(luai_numdiv) -#define luai_numdiv(L,a,b) ((a)/(b)) +#define luai_numdiv(L,a,b) ((void)L, (a)/(b)) #endif /* @@ -267,10 +267,10 @@ typedef unsigned long l_uint32; /* the others are quite standard operations */ #if !defined(luai_numadd) -#define luai_numadd(L,a,b) ((a)+(b)) -#define luai_numsub(L,a,b) ((a)-(b)) -#define luai_nummul(L,a,b) ((a)*(b)) -#define luai_numunm(L,a) (-(a)) +#define luai_numadd(L,a,b) ((void)L, (a)+(b)) +#define luai_numsub(L,a,b) ((void)L, (a)-(b)) +#define luai_nummul(L,a,b) ((void)L, (a)*(b)) +#define luai_numunm(L,a) ((void)L, -(a)) #define luai_numeq(a,b) ((a)==(b)) #define luai_numlt(a,b) ((a)<(b)) #define luai_numle(a,b) ((a)<=(b)) diff --git a/lua-5.5.0/lmathlib.c b/lua-5.5.1/lmathlib.c similarity index 100% rename from lua-5.5.0/lmathlib.c rename to lua-5.5.1/lmathlib.c diff --git a/lua-5.5.0/lmem.c b/lua-5.5.1/lmem.c similarity index 100% rename from lua-5.5.0/lmem.c rename to lua-5.5.1/lmem.c diff --git a/lua-5.5.0/lmem.h b/lua-5.5.1/lmem.h similarity index 100% rename from lua-5.5.0/lmem.h rename to lua-5.5.1/lmem.h diff --git a/lua-5.5.0/loadlib.c b/lua-5.5.1/loadlib.c similarity index 99% rename from lua-5.5.0/loadlib.c rename to lua-5.5.1/loadlib.c index 8d2e68e..ef09c9a 100644 --- a/lua-5.5.0/loadlib.c +++ b/lua-5.5.1/loadlib.c @@ -541,7 +541,7 @@ static int searcher_Lua (lua_State *L) { const char *name = luaL_checkstring(L, 1); filename = findfile(L, name, "path", LUA_LSUBSEP); if (filename == NULL) return 1; /* module not found in this path */ - return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename); + return checkload(L, (luaL_loadfilex(L, filename, "bt") == LUA_OK), filename); } diff --git a/lua-5.5.0/lobject.c b/lua-5.5.1/lobject.c similarity index 100% rename from lua-5.5.0/lobject.c rename to lua-5.5.1/lobject.c diff --git a/lua-5.5.0/lobject.h b/lua-5.5.1/lobject.h similarity index 99% rename from lua-5.5.0/lobject.h rename to lua-5.5.1/lobject.h index 156c942..bf5b65b 100644 --- a/lua-5.5.0/lobject.h +++ b/lua-5.5.1/lobject.h @@ -208,7 +208,8 @@ typedef union { #define ttisstrictnil(o) checktag((o), LUA_VNIL) -#define setnilvalue(obj) settt_(obj, LUA_VNIL) +#define setnilvalue(obj) settt_(obj, LUA_VNIL) +#define setnilvalue2s(stk) setnilvalue(s2v(stk)) #define isabstkey(v) checktag((v), LUA_VABSTKEY) diff --git a/lua-5.5.0/lopcodes.c b/lua-5.5.1/lopcodes.c similarity index 89% rename from lua-5.5.0/lopcodes.c rename to lua-5.5.1/lopcodes.c index 7e18231..bb1a416 100644 --- a/lua-5.5.0/lopcodes.c +++ b/lua-5.5.1/lopcodes.c @@ -104,35 +104,26 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { ,opmode(0, 1, 0, 0, 1, iABC) /* OP_VARARG */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETVARG */ ,opmode(0, 0, 0, 0, 0, iABx) /* OP_ERRNNIL */ - ,opmode(0, 0, 1, 0, 1, iABC) /* OP_VARARGPREP */ + ,opmode(0, 0, 0, 0, 0, iABC) /* OP_VARARGPREP */ ,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */ }; - -/* -** Check whether instruction sets top for next instruction, that is, -** it results in multiple values. -*/ -int luaP_isOT (Instruction i) { - OpCode op = GET_OPCODE(i); - switch (op) { - case OP_TAILCALL: return 1; - default: - return testOTMode(op) && GETARG_C(i) == 0; - } -} +#define testITMode(m) (luaP_opmodes[m] & (1 << 5)) /* -** Check whether instruction uses top from previous instruction, that is, -** it accepts multiple results. +** Check whether instruction uses top. That happens for OP_VARARGPREP +** and for instructions that use multiple values set by the previous +** instruction. */ int luaP_isIT (Instruction i) { OpCode op = GET_OPCODE(i); switch (op) { case OP_SETLIST: - return testITMode(GET_OPCODE(i)) && GETARG_vB(i) == 0; + return GETARG_vB(i) == 0; + case OP_VARARGPREP: + return 1; default: return testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0; } diff --git a/lua-5.5.0/lopcodes.h b/lua-5.5.1/lopcodes.h similarity index 97% rename from lua-5.5.0/lopcodes.h rename to lua-5.5.1/lopcodes.h index b6bd182..86cff06 100644 --- a/lua-5.5.0/lopcodes.h +++ b/lua-5.5.1/lopcodes.h @@ -417,8 +417,8 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ ** bits 0-2: op mode ** bit 3: instruction set register A ** bit 4: operator is a test (next instruction must be a jump) -** bit 5: instruction uses 'L->top' set by previous instruction (when B == 0) -** bit 6: instruction sets 'L->top' for next instruction (when C == 0) +** bit 5: used by 'luaP_isIT' +** bit 6: used by 'luaP_isOT' ** bit 7: instruction is an MM instruction (call a metamethod) */ @@ -427,12 +427,17 @@ LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];) #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 7)) #define testAMode(m) (luaP_opmodes[m] & (1 << 3)) #define testTMode(m) (luaP_opmodes[m] & (1 << 4)) -#define testITMode(m) (luaP_opmodes[m] & (1 << 5)) -#define testOTMode(m) (luaP_opmodes[m] & (1 << 6)) #define testMMMode(m) (luaP_opmodes[m] & (1 << 7)) -LUAI_FUNC int luaP_isOT (Instruction i); +/* Check whether instruction sets top for next instruction, that is, +** it results in multiple values. Used only for tests. +*/ +#define luaP_isOT(i) \ + (GET_OPCODE(i) == OP_TAILCALL || \ + ((luaP_opmodes[GET_OPCODE(i)] & (1 << 6)) && GETARG_C(i) == 0)) + + LUAI_FUNC int luaP_isIT (Instruction i); diff --git a/lua-5.5.0/lopnames.h b/lua-5.5.1/lopnames.h similarity index 100% rename from lua-5.5.0/lopnames.h rename to lua-5.5.1/lopnames.h diff --git a/lua-5.5.0/loslib.c b/lua-5.5.1/loslib.c similarity index 99% rename from lua-5.5.0/loslib.c rename to lua-5.5.1/loslib.c index e76e2c5..e923678 100644 --- a/lua-5.5.0/loslib.c +++ b/lua-5.5.1/loslib.c @@ -439,4 +439,3 @@ LUAMOD_API int luaopen_os (lua_State *L) { luaL_newlib(L, syslib); return 1; } - diff --git a/lua-5.5.0/lparser.c b/lua-5.5.1/lparser.c similarity index 99% rename from lua-5.5.0/lparser.c rename to lua-5.5.1/lparser.c index b3855d4..3c26a4f 100644 --- a/lua-5.5.0/lparser.c +++ b/lua-5.5.1/lparser.c @@ -821,8 +821,7 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { luaC_objbarrier(L, f, f->source); f->maxstacksize = 2; /* registers 0/1 are always valid */ fs->kcache = luaH_new(L); /* create table for function */ - sethvalue2s(L, L->top.p, fs->kcache); /* anchor it */ - luaD_inctop(L); + luaD_anchorobj(L, ls->h, obj2gco(fs->kcache)); /* anchor it */ enterblock(fs, bl, 0); } @@ -831,6 +830,7 @@ static void close_func (LexState *ls) { lua_State *L = ls->L; FuncState *fs = ls->fs; Proto *f = fs->f; + TValue temp; luaK_ret(fs, luaY_nvarstack(fs), 0); /* final return */ leaveblock(fs); lua_assert(fs->bl == NULL); @@ -843,8 +843,10 @@ static void close_func (LexState *ls) { luaM_shrinkvector(L, f->p, f->sizep, fs->np, Proto *); luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->ndebugvars, LocVar); luaM_shrinkvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc); + /* remove kcache table from scanner table ("weigh" its anchor) */ + sethvalue(L, &temp, fs->kcache); /* key to be set to nil */ + luaH_set(L, ls->h, &temp, &G(L)->nilvalue); ls->fs = fs->prev; - L->top.p--; /* pop kcache table */ luaC_checkGC(L); } @@ -1164,6 +1166,7 @@ static void funcargs (LexState *ls, expdesc *f) { } default: { luaX_syntaxerror(ls, "function arguments expected"); + return; /* to avoid warnings */ } } lua_assert(f->k == VNONRELOC); @@ -1611,7 +1614,6 @@ static void repeatstat (LexState *ls, int line) { statlist(ls); check_match(ls, TK_UNTIL, TK_REPEAT, line); condexit = cond(ls); /* read condition (inside scope block) */ - leaveblock(fs); /* finish scope */ if (bl2.upval) { /* upvalues? */ int exit = luaK_jump(fs); /* normal exit must jump over fix */ luaK_patchtohere(fs, condexit); /* repetition must close upvalues */ @@ -1620,6 +1622,7 @@ static void repeatstat (LexState *ls, int line) { luaK_patchtohere(fs, exit); /* normal exit comes to here */ } luaK_patchlist(fs, condexit, repeat_init); /* close the loop */ + leaveblock(fs); /* finish scope */ leaveblock(fs); /* finish loop */ } @@ -2111,7 +2114,7 @@ static void statement (LexState *ls) { gotostat(ls, line); break; } -#if defined(LUA_COMPAT_GLOBAL) +#if LUA_COMPAT_GLOBAL case TK_NAME: { /* compatibility code to parse global keyword when "global" is not reserved */ @@ -2165,16 +2168,14 @@ static void mainfunc (LexState *ls, FuncState *fs) { } -LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, +LClosure *luaY_parser (lua_State *L, ZIO *z, Table *anchor, Mbuffer *buff, Dyndata *dyd, const char *name, int firstchar) { LexState lexstate; FuncState funcstate; - LClosure *cl = luaF_newLclosure(L, 1); /* create main closure */ - setclLvalue2s(L, L->top.p, cl); /* anchor it (to avoid being collected) */ - luaD_inctop(L); - lexstate.h = luaH_new(L); /* create table for scanner */ - sethvalue2s(L, L->top.p, lexstate.h); /* anchor it */ - luaD_inctop(L); + LClosure *cl; + lexstate.h = anchor; /* table for scanner */ + cl = luaF_newLclosure(L, 1); /* create main closure */ + luaD_anchorobj(L, anchor, obj2gco(cl)); /* anchor it in scanner table */ funcstate.f = cl->p = luaF_newproto(L); luaC_objbarrier(L, cl, cl->p); funcstate.f->source = luaS_new(L, name); /* create and anchor TString */ @@ -2187,7 +2188,6 @@ LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); /* all scopes should be correctly finished */ lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0); - L->top.p--; /* remove scanner's table */ - return cl; /* closure is on the stack, too */ + return cl; } diff --git a/lua-5.5.0/lparser.h b/lua-5.5.1/lparser.h similarity index 97% rename from lua-5.5.0/lparser.h rename to lua-5.5.1/lparser.h index a30df04..4fad6bd 100644 --- a/lua-5.5.0/lparser.h +++ b/lua-5.5.1/lparser.h @@ -189,8 +189,9 @@ typedef struct FuncState { LUAI_FUNC lu_byte luaY_nvarstack (FuncState *fs); LUAI_FUNC void luaY_checklimit (FuncState *fs, int v, int l, const char *what); -LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, - Dyndata *dyd, const char *name, int firstchar); +LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Table *anchor, + Mbuffer *buff, Dyndata *dyd, + const char *name, int firstchar); #endif diff --git a/lua-5.5.0/lprefix.h b/lua-5.5.1/lprefix.h similarity index 100% rename from lua-5.5.0/lprefix.h rename to lua-5.5.1/lprefix.h diff --git a/lua-5.5.0/lstate.c b/lua-5.5.1/lstate.c similarity index 95% rename from lua-5.5.0/lstate.c rename to lua-5.5.1/lstate.c index 70a11aa..ada0b85 100644 --- a/lua-5.5.0/lstate.c +++ b/lua-5.5.1/lstate.c @@ -68,14 +68,19 @@ void luaE_setdebt (global_State *g, l_mem debt) { } -CallInfo *luaE_extendCI (lua_State *L) { +CallInfo *luaE_extendCI (lua_State *L, int err) { CallInfo *ci; - lua_assert(L->ci->next == NULL); - ci = luaM_new(L, CallInfo); - lua_assert(L->ci->next == NULL); - L->ci->next = ci; + ci = luaM_reallocvector(L, NULL, 0, 1, CallInfo); + if (l_unlikely(ci == NULL)) { /* allocation failed? */ + if (err) + luaM_error(L); /* raise the error */ + return NULL; /* else only report it */ + } + ci->next = L->ci->next; ci->previous = L->ci; - ci->next = NULL; + L->ci->next = ci; + if (ci->next) + ci->next->previous = ci; ci->u.l.trap = 0; L->nci++; return ci; @@ -146,7 +151,7 @@ LUAI_FUNC void luaE_incCstack (lua_State *L) { static void resetCI (lua_State *L) { CallInfo *ci = L->ci = &L->base_ci; ci->func.p = L->stack.p; - setnilvalue(s2v(ci->func.p)); /* 'function' entry for basic 'ci' */ + setnilvalue2s(ci->func.p); /* 'function' entry for basic 'ci' */ ci->top.p = ci->func.p + 1 + LUA_MINSTACK; /* +1 for 'function' entry */ ci->u.c.k = NULL; ci->callstatus = CIST_C; @@ -161,7 +166,7 @@ static void stack_init (lua_State *L1, lua_State *L) { L1->stack.p = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue); L1->tbclist.p = L1->stack.p; for (i = 0; i < BASIC_STACK_SIZE + EXTRA_STACK; i++) - setnilvalue(s2v(L1->stack.p + i)); /* erase new stack */ + setnilvalue2s(L1->stack.p + i); /* erase new stack */ L1->stack_last.p = L1->stack.p + BASIC_STACK_SIZE; /* initialize first ci */ resetCI(L1); diff --git a/lua-5.5.0/lstate.h b/lua-5.5.1/lstate.h similarity index 92% rename from lua-5.5.0/lstate.h rename to lua-5.5.1/lstate.h index 20dc4d2..30a560a 100644 --- a/lua-5.5.0/lstate.h +++ b/lua-5.5.1/lstate.h @@ -383,7 +383,7 @@ typedef struct global_State { /* -** Union of all collectable objects (only for conversions) +** Union of all collectable objects ** ISO C99, 6.5.2.3 p.5: ** "if a union contains several structures that share a common initial ** sequence [...], and if the union object currently contains one @@ -403,32 +403,32 @@ union GCUnion { }; -/* -** ISO C99, 6.7.2.1 p.14: -** "A pointer to a union object, suitably converted, points to each of -** its members [...], and vice versa." +/* macros to convert a GCObject into a specific value +** ISO C99, 6.3.2.2 p.7: +** "A pointer to an object or incomplete type may be converted to a +** pointer to a different object or incomplete type. If the resulting +** pointer is not correctly aligned for the pointed-to type, the +** behavior is undefined. Otherwise, when converted back again, the +** result shall compare equal to the original pointer." */ -#define cast_u(o) cast(union GCUnion *, (o)) - -/* macros to convert a GCObject into a specific value */ -#define gco2ts(o) \ - check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts)) -#define gco2u(o) check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u)) -#define gco2lcl(o) check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l)) -#define gco2ccl(o) check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c)) -#define gco2cl(o) \ - check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl)) -#define gco2t(o) check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h)) -#define gco2p(o) check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p)) -#define gco2th(o) check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th)) -#define gco2upv(o) check_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv)) +#define gco2(v,T,o) check_exp((o)->tt == v, cast(T*, o)) +#define gco2nv(t,T,o) check_exp(novariant((o)->tt) == t, cast(T*, o)) +#define gco2ts(o) gco2nv(LUA_TSTRING, TString, o) +#define gco2u(o) gco2(LUA_VUSERDATA, Udata, o) +#define gco2lcl(o) (&gco2(LUA_VLCL, Closure, o)->l) +#define gco2ccl(o) (&gco2(LUA_VCCL, Closure, o)->c) +#define gco2cl(o) gco2nv(LUA_TFUNCTION, Closure, o) +#define gco2t(o) gco2(LUA_VTABLE, Table, o) +#define gco2p(o) gco2(LUA_VPROTO, Proto, o) +#define gco2th(o) gco2(LUA_VTHREAD, lua_State, o) +#define gco2upv(o) gco2(LUA_VUPVAL, UpVal, o) /* ** macro to convert a Lua object into a GCObject */ #define obj2gco(v) \ - check_exp(novariant((v)->tt) >= LUA_TSTRING, &(cast_u(v)->gc)) + check_exp(novariant((v)->tt) >= LUA_TSTRING, cast(GCObject*, v)) /* actual number of total memory allocated */ @@ -438,7 +438,7 @@ union GCUnion { LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); LUAI_FUNC lu_mem luaE_threadsize (lua_State *L); -LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); +LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L, int err); LUAI_FUNC void luaE_shrinkCI (lua_State *L); LUAI_FUNC void luaE_checkcstack (lua_State *L); LUAI_FUNC void luaE_incCstack (lua_State *L); diff --git a/lua-5.5.0/lstring.c b/lua-5.5.1/lstring.c similarity index 100% rename from lua-5.5.0/lstring.c rename to lua-5.5.1/lstring.c diff --git a/lua-5.5.0/lstring.h b/lua-5.5.1/lstring.h similarity index 100% rename from lua-5.5.0/lstring.h rename to lua-5.5.1/lstring.h diff --git a/lua-5.5.0/lstrlib.c b/lua-5.5.1/lstrlib.c similarity index 99% rename from lua-5.5.0/lstrlib.c rename to lua-5.5.1/lstrlib.c index 23df839..dd3c0fd 100644 --- a/lua-5.5.0/lstrlib.c +++ b/lua-5.5.1/lstrlib.c @@ -141,8 +141,8 @@ static int str_rep (lua_State *L) { const char *s = luaL_checklstring(L, 1, &len); lua_Integer n = luaL_checkinteger(L, 2); const char *sep = luaL_optlstring(L, 3, "", &lsep); - if (n <= 0) - lua_pushliteral(L, ""); + if (n <= 0 || (len | lsep) == 0) + lua_pushliteral(L, ""); /* no repetitions or both strings empty */ else if (l_unlikely(len > MAX_SIZE - lsep || cast_st2S(len + lsep) > cast_st2S(MAX_SIZE) / n)) return luaL_error(L, "resulting string too large"); @@ -757,19 +757,25 @@ static int nospecials (const char *p, size_t l) { } +/* +** Prepare state for matches. These fields are not affected by each match. +*/ static void prepstate (MatchState *ms, lua_State *L, const char *s, size_t ls, const char *p, size_t lp) { ms->L = L; - ms->matchdepth = MAXCCALLS; ms->src_init = s; ms->src_end = s + ls; ms->p_end = p + lp; } +/* +** (Re)prepare state for a match, setting fields that change during +** each match. +*/ static void reprepstate (MatchState *ms) { + ms->matchdepth = MAXCCALLS; ms->level = 0; - lua_assert(ms->matchdepth == MAXCCALLS); } @@ -968,7 +974,7 @@ static int str_gsub (lua_State *L) { reprepstate(&ms); /* (re)prepare state for new match */ if ((e = match(&ms, src, p)) != NULL && e != lastmatch) { /* match? */ n++; - changed = add_value(&ms, &b, src, e, tr) | changed; + changed = add_value(&ms, &b, src, e, tr) || changed; src = lastmatch = e; } else if (src < ms.src_end) /* otherwise, skip one character */ @@ -1726,7 +1732,7 @@ static int str_packsize (lua_State *L) { luaL_argcheck(L, opt != Kstring && opt != Kzstr, 1, "variable-length format"); size += ntoalign; /* total space used by option */ - luaL_argcheck(L, totalsize <= LUA_MAXINTEGER - size, + luaL_argcheck(L, totalsize <= MAX_SIZE - size, 1, "format result too large"); totalsize += size; } diff --git a/lua-5.5.0/ltable.c b/lua-5.5.1/ltable.c similarity index 99% rename from lua-5.5.0/ltable.c rename to lua-5.5.1/ltable.c index b7f88f6..2f2b5c1 100644 --- a/lua-5.5.0/ltable.c +++ b/lua-5.5.1/ltable.c @@ -651,10 +651,9 @@ static void reinserthash (lua_State *L, Table *ot, Table *t) { /* -** Exchange the hash part of 't1' and 't2'. (In 'flags', only the -** dummy bit must be exchanged: The 'isrealasize' is not related -** to the hash part, and the metamethod bits do not change during -** a resize, so the "real" table can keep their values.) +** Exchange the hash part of 't1' and 't2'. (In 'flags', only the dummy +** bit must be exchanged: The metamethod bits do not change during a +** resize, so the "real" table can keep their values.) */ static void exchangehashpart (Table *t1, Table *t2) { lu_byte lsizenode = t1->lsizenode; @@ -1156,14 +1155,15 @@ void luaH_finishset (lua_State *L, Table *t, const TValue *key, lua_assert(hres != HOK); if (hres == HNOTFOUND) { TValue aux; + const TValue *actk = key; /* actual key to insert */ if (l_unlikely(ttisnil(key))) luaG_runerror(L, "table index is nil"); else if (ttisfloat(key)) { lua_Number f = fltvalue(key); lua_Integer k; - if (luaV_flttointeger(f, &k, F2Ieq)) { - setivalue(&aux, k); /* key is equal to an integer */ - key = &aux; /* insert it as an integer */ + if (luaV_flttointeger(f, &k, F2Ieq)) { /* is key equal to an integer? */ + setivalue(&aux, k); + actk = &aux; /* use the integer as the key */ } else if (l_unlikely(luai_numisnan(f))) luaG_runerror(L, "table index is NaN"); @@ -1176,7 +1176,7 @@ void luaH_finishset (lua_State *L, Table *t, const TValue *key, L->top.p--; return; } - luaH_newkey(L, t, key, value); + luaH_newkey(L, t, actk, value); } else if (hres > 0) { /* regular Node? */ setobj2t(L, gval(gnode(t, hres - HFIRSTNODE)), value); diff --git a/lua-5.5.0/ltable.h b/lua-5.5.1/ltable.h similarity index 100% rename from lua-5.5.0/ltable.h rename to lua-5.5.1/ltable.h diff --git a/lua-5.5.0/ltablib.c b/lua-5.5.1/ltablib.c similarity index 97% rename from lua-5.5.0/ltablib.c rename to lua-5.5.1/ltablib.c index 29bbd63..fb06218 100644 --- a/lua-5.5.0/ltablib.c +++ b/lua-5.5.1/ltablib.c @@ -46,15 +46,17 @@ static int checkfield (lua_State *L, const char *key, int n) { /* ** Check that 'arg' either is a table or can behave like one (that is, -** has a metatable with the required metamethods) +** has a metatable with the required metamethods). */ static void checktab (lua_State *L, int arg, int what) { - if (lua_type(L, arg) != LUA_TTABLE) { /* is it not a table? */ + int tp = lua_type(L, arg); + if (tp != LUA_TTABLE) { /* is it not a table? */ int n = 1; /* number of elements to pop */ if (lua_getmetatable(L, arg) && /* must have metatable */ (!(what & TAB_R) || checkfield(L, "__index", ++n)) && (!(what & TAB_W) || checkfield(L, "__newindex", ++n)) && - (!(what & TAB_L) || checkfield(L, "__len", ++n))) { + (!(what & TAB_L) || /* strings don't need '__len' to have a length */ + tp == LUA_TSTRING || checkfield(L, "__len", ++n))) { lua_pop(L, n); /* pop metatable and tested metamethods */ } else @@ -208,8 +210,9 @@ static int tpack (lua_State *L) { static int tunpack (lua_State *L) { lua_Unsigned n; + lua_Integer len = aux_getn(L, 1, TAB_R); lua_Integer i = luaL_optinteger(L, 2, 1); - lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1)); + lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, len); if (i > e) return 0; /* empty range */ n = l_castS2U(e) - l_castS2U(i); /* number of elements minus 1 */ if (l_unlikely(n >= (unsigned int)INT_MAX || @@ -427,4 +430,3 @@ LUAMOD_API int luaopen_table (lua_State *L) { luaL_newlib(L, tab_funcs); return 1; } - diff --git a/lua-5.5.0/ltm.c b/lua-5.5.1/ltm.c similarity index 97% rename from lua-5.5.0/ltm.c rename to lua-5.5.1/ltm.c index f2a373f..cfe90e3 100644 --- a/lua-5.5.0/ltm.c +++ b/lua-5.5.1/ltm.c @@ -262,7 +262,7 @@ static void buildhiddenargs (lua_State *L, CallInfo *ci, const Proto *p, /* move fixed parameters to after the copied function */ for (i = 1; i <= nfixparams; i++) { setobjs2s(L, L->top.p++, ci->func.p + i); - setnilvalue(s2v(ci->func.p + i)); /* erase original parameter (for GC) */ + setnilvalue2s(ci->func.p + i); /* erase original parameter (for GC) */ } ci->func.p += totalargs + 1; /* 'func' now lives after hidden arguments */ ci->top.p += totalargs + 1; @@ -283,7 +283,7 @@ void luaT_adjustvarargs (lua_State *L, CallInfo *ci, const Proto *p) { lua_assert(p->flag & PF_VAHID); buildhiddenargs(L, ci, p, totalargs, nfixparams, nextra); /* set vararg parameter to nil */ - setnilvalue(s2v(ci->func.p + nfixparams + 1)); + setnilvalue2s(ci->func.p + nfixparams + 1); lua_assert(L->top.p <= ci->top.p && ci->top.p <= L->stack_last.p); } } @@ -307,7 +307,7 @@ void luaT_getvararg (CallInfo *ci, StkId ra, TValue *rc) { return; } } - setnilvalue(s2v(ra)); /* else produce nil */ + setnilvalue2s(ra); /* else produce nil */ } @@ -355,10 +355,10 @@ void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted, for (i = 0; i < touse; i++) { lu_byte tag = luaH_getint(h, i + 1, s2v(where + i)); if (tagisempty(tag)) - setnilvalue(s2v(where + i)); + setnilvalue2s(where + i); } } for (; i < wanted; i++) /* complete required results with nil */ - setnilvalue(s2v(where + i)); + setnilvalue2s(where + i); } diff --git a/lua-5.5.0/ltm.h b/lua-5.5.1/ltm.h similarity index 97% rename from lua-5.5.0/ltm.h rename to lua-5.5.1/ltm.h index 07fc8c1..afc7ad0 100644 --- a/lua-5.5.0/ltm.h +++ b/lua-5.5.1/ltm.h @@ -49,7 +49,7 @@ typedef enum { ** Mask with 1 in all fast-access methods. A 1 in any of these bits ** in the flag of a (meta)table means the metatable does not have the ** corresponding metamethod field. (Bit 6 of the flag indicates that -** the table is using the dummy node; bit 7 is used for 'isrealasize'.) +** the table is using the dummy node.) */ #define maskflags cast_byte(~(~0u << (TM_EQ + 1))) diff --git a/lua-5.5.0/lua.h b/lua-5.5.1/lua.h similarity index 99% rename from lua-5.5.0/lua.h rename to lua-5.5.1/lua.h index ab473dc..6deaed4 100644 --- a/lua-5.5.0/lua.h +++ b/lua-5.5.1/lua.h @@ -13,13 +13,13 @@ #include -#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2025 Lua.org, PUC-Rio" +#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2026 Lua.org, PUC-Rio" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes" #define LUA_VERSION_MAJOR_N 5 #define LUA_VERSION_MINOR_N 5 -#define LUA_VERSION_RELEASE_N 0 +#define LUA_VERSION_RELEASE_N 1 #define LUA_VERSION_NUM (LUA_VERSION_MAJOR_N * 100 + LUA_VERSION_MINOR_N) #define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + LUA_VERSION_RELEASE_N) @@ -521,7 +521,7 @@ struct lua_Debug { /****************************************************************************** -* Copyright (C) 1994-2025 Lua.org, PUC-Rio. +* Copyright (C) 1994-2026 Lua.org, PUC-Rio. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/lua-5.5.0/luaconf.h b/lua-5.5.1/luaconf.h similarity index 95% rename from lua-5.5.0/luaconf.h rename to lua-5.5.1/luaconf.h index 96a7780..bdac085 100644 --- a/lua-5.5.0/luaconf.h +++ b/lua-5.5.1/luaconf.h @@ -70,14 +70,16 @@ #if defined(LUA_USE_LINUX) #define LUA_USE_POSIX #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ +#if !defined(LUA_READLINELIB) #define LUA_READLINELIB "libreadline.so" #endif +#endif #if defined(LUA_USE_MACOSX) #define LUA_USE_POSIX #define LUA_USE_DLOPEN /* macOS does not need -ldl */ -#define LUA_READLINELIB "libedit.dylib" +#define LUA_USE_READLINE /* needs an extra library: -lreadline */ #endif @@ -224,17 +226,17 @@ #if !defined(LUA_PATH_DEFAULT) #define LUA_PATH_DEFAULT \ - LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ - LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \ - LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \ + LUA_LDIR "?.lua;" LUA_LDIR "?\\init.lua;" \ + LUA_CDIR "?.lua;" LUA_CDIR "?\\init.lua;" \ + LUA_SHRDIR "?.lua;" LUA_SHRDIR "?\\init.lua;" \ ".\\?.lua;" ".\\?\\init.lua" #endif #if !defined(LUA_CPATH_DEFAULT) #define LUA_CPATH_DEFAULT \ - LUA_CDIR"?.dll;" \ - LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \ - LUA_CDIR"loadall.dll;" ".\\?.dll" + LUA_CDIR "?.dll;" \ + LUA_CDIR "..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \ + LUA_CDIR "loadall.dll;" ".\\?.dll" #endif #else /* }{ */ @@ -245,14 +247,14 @@ #if !defined(LUA_PATH_DEFAULT) #define LUA_PATH_DEFAULT \ - LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ - LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \ + LUA_LDIR "?.lua;" LUA_LDIR "?/init.lua;" \ + LUA_CDIR "?.lua;" LUA_CDIR "?/init.lua;" \ "./?.lua;" "./?/init.lua" #endif #if !defined(LUA_CPATH_DEFAULT) #define LUA_CPATH_DEFAULT \ - LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so" + LUA_CDIR "?.so;" LUA_CDIR "loadall.so;" "./?.so" #endif #endif /* } */ @@ -339,7 +341,9 @@ /* @@ LUA_COMPAT_GLOBAL avoids 'global' being a reserved word */ -#define LUA_COMPAT_GLOBAL +#if !defined(LUA_COMPAT_GLOBAL) +#define LUA_COMPAT_GLOBAL 1 +#endif /* @@ -649,7 +653,7 @@ */ #if !defined(luai_likely) -#if defined(__GNUC__) && !defined(LUA_NOBUILTIN) +#if !defined(LUA_NOBUILTIN) && defined(__GNUC__) && (__GNUC__ >= 3) #define luai_likely(x) (__builtin_expect(((x) != 0), 1)) #define luai_unlikely(x) (__builtin_expect(((x) != 0), 0)) #else @@ -721,10 +725,17 @@ /* -@@ LUAI_MAXALIGN defines fields that, when used in a union, ensure -** maximum alignment for the other items in that union. +@@ LUAI_MAXALIGN defines fields that ensure proper alignment for +** memory areas offered by Lua (e.g., userdata memory). +** Add fields to it if you need alignment for non-ISO objects. */ +#if defined(LLONG_MAX) +/* use ISO C99 stuff */ +#define LUAI_MAXALIGN long double u; void *s; long long l +#else +/* use only C89 stuff */ #define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l +#endif /* }================================================================== */ diff --git a/lua-5.5.0/lualib.h b/lua-5.5.1/lualib.h similarity index 100% rename from lua-5.5.0/lualib.h rename to lua-5.5.1/lualib.h diff --git a/lua-5.5.0/lundump.c b/lua-5.5.1/lundump.c similarity index 97% rename from lua-5.5.0/lundump.c rename to lua-5.5.1/lundump.c index 3b61cc8..d5fdc64 100644 --- a/lua-5.5.0/lundump.c +++ b/lua-5.5.1/lundump.c @@ -392,7 +392,8 @@ static void checkHeader (LoadState *S) { /* ** Load precompiled chunk. */ -LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) { +LClosure *luaU_undump (lua_State *L, ZIO *Z, Table *anchor, const char *name, + int fixed) { LoadState S; LClosure *cl; if (*name == '@' || *name == '=') @@ -405,20 +406,16 @@ LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) { S.fixed = cast_byte(fixed); S.offset = 1; /* fist byte was already read */ checkHeader(&S); - cl = luaF_newLclosure(L, loadByte(&S)); - setclLvalue2s(L, L->top.p, cl); - luaD_inctop(L); - S.h = luaH_new(L); /* create list of saved strings */ + S.h = anchor; S.nstr = 0; - sethvalue2s(L, L->top.p, S.h); /* anchor it */ - luaD_inctop(L); + cl = luaF_newLclosure(L, loadByte(&S)); + luaD_anchorobj(L, anchor, obj2gco(cl)); cl->p = luaF_newproto(L); luaC_objbarrier(L, cl, cl->p); loadFunction(&S, cl->p); if (cl->nupvalues != cl->p->sizeupvalues) error(&S, "corrupted chunk"); luai_verifycode(L, cl->p); - L->top.p--; /* pop table */ return cl; } diff --git a/lua-5.5.0/lundump.h b/lua-5.5.1/lundump.h similarity index 85% rename from lua-5.5.0/lundump.h rename to lua-5.5.1/lundump.h index c4e06f9..186e25f 100644 --- a/lua-5.5.0/lundump.h +++ b/lua-5.5.1/lundump.h @@ -30,8 +30,8 @@ /* load one chunk; from lundump.c */ -LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name, - int fixed); +LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, Table *anchor, + const char* name, int fixed); /* dump one chunk; from ldump.c */ LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, diff --git a/lua-5.5.0/lutf8lib.c b/lua-5.5.1/lutf8lib.c similarity index 97% rename from lua-5.5.0/lutf8lib.c rename to lua-5.5.1/lutf8lib.c index b7f3fe1..0cd7f9c 100644 --- a/lua-5.5.0/lutf8lib.c +++ b/lua-5.5.1/lutf8lib.c @@ -56,6 +56,8 @@ static const char *utf8_decode (const char *s, l_uint32 *val, int strict) { l_uint32 res = 0; /* final result */ if (c < 0x80) /* ASCII? */ res = c; + else if (c >= 0xfe) /* c >= 1111 1110b ? */ + return NULL; /* would need six or more continuation bytes */ else { int count = 0; /* to count number of continuation bytes */ for (; c & 0x40; c <<= 1) { /* while it needs continuation bytes... */ @@ -64,8 +66,9 @@ static const char *utf8_decode (const char *s, l_uint32 *val, int strict) { return NULL; /* invalid byte sequence */ res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ } + lua_assert(count <= 5); res |= ((l_uint32)(c & 0x7F) << (count * 5)); /* add first byte */ - if (count > 5 || res > MAXUTF || res < limits[count]) + if (res > MAXUTF || res < limits[count]) return NULL; /* invalid byte sequence */ s += count; /* skip continuation bytes read */ } @@ -146,7 +149,7 @@ static int codepoint (lua_State *L) { static void pushutfchar (lua_State *L, int arg) { lua_Unsigned code = (lua_Unsigned)luaL_checkinteger(L, arg); luaL_argcheck(L, code <= MAXUTF, arg, "value out of range"); - lua_pushfstring(L, "%U", (long)code); + lua_pushfstring(L, "%U", cast(unsigned long, code)); } diff --git a/lua-5.5.0/lvm.c b/lua-5.5.1/lvm.c similarity index 98% rename from lua-5.5.0/lvm.c rename to lua-5.5.1/lvm.c index c70e2b8..986c7db 100644 --- a/lua-5.5.0/lvm.c +++ b/lua-5.5.1/lvm.c @@ -268,9 +268,9 @@ static int forprep (lua_State *L, StkId ra) { /* ** Execute a step of a float numerical for loop, returning ** true iff the loop must continue. (The integer case is -** written online with opcode OP_FORLOOP, for performance.) +** written inline with opcode OP_FORLOOP, for performance.) */ -static int floatforloop (StkId ra) { +static int floatforloop (lua_State *L, StkId ra) { lua_Number step = fltvalue(s2v(ra + 1)); lua_Number limit = fltvalue(s2v(ra)); lua_Number idx = fltvalue(s2v(ra + 2)); /* control variable */ @@ -303,7 +303,7 @@ lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key, else { /* 't' is a table */ tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ if (tm == NULL) { /* no metamethod? */ - setnilvalue(s2v(val)); /* result is nil */ + setnilvalue2s(val); /* result is nil */ return LUA_VNIL; } /* else will try the metamethod */ @@ -360,13 +360,19 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key, luaT_callTM(L, tm, t, key, val); return; } - t = tm; /* else repeat assignment over 'tm' */ - luaV_fastset(t, key, val, hres, luaH_pset); - if (hres == HOK) { - luaV_finishfastset(L, t, val); - return; /* done */ + t = tm; /* else must repeat assignment over 'tm' */ + /* do the equivalent to 'luaV_fastset', but saving 'h' */ + if (!ttistable(t)) + hres = HNOTATABLE; + else { + Table *h = hvalue(t); /* next call can change the value at 't' */ + hres = luaH_pset(h, key, val); + if (hres == HOK) { + luaC_barrierback(L, obj2gco(h), val); /* luaV_finishfastset */ + return; /* done */ + } } - /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */ + /* else 'return luaV_finishset(L, t, key, val, hres)' (loop) */ } luaG_runerror(L, "'__newindex' chain too long; possible loop"); } @@ -919,7 +925,7 @@ void luaV_finishOp (lua_State *L) { ** Macros for arithmetic/bitwise/comparison opcodes in 'luaV_execute' ** ** All these macros are to be used exclusively inside the main -** iterpreter loop (function luaV_execute) and may access directly +** interpreter loop (function luaV_execute) and may access directly ** the local variables of that function (L, i, pc, ci, etc.). ** =================================================================== */ @@ -1841,7 +1847,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { pc -= GETARG_Bx(i); /* jump back */ } } - else if (floatforloop(ra)) /* float loop */ + else if (floatforloop(L, ra)) /* float loop */ pc -= GETARG_Bx(i); /* jump back */ updatetrap(ci); /* allows a signal to break the loop */ vmbreak; diff --git a/lua-5.5.0/lvm.h b/lua-5.5.1/lvm.h similarity index 100% rename from lua-5.5.0/lvm.h rename to lua-5.5.1/lvm.h diff --git a/lua-5.5.0/lzio.c b/lua-5.5.1/lzio.c similarity index 100% rename from lua-5.5.0/lzio.c rename to lua-5.5.1/lzio.c diff --git a/lua-5.5.0/lzio.h b/lua-5.5.1/lzio.h similarity index 100% rename from lua-5.5.0/lzio.h rename to lua-5.5.1/lzio.h diff --git a/src/lib.rs b/src/lib.rs index 75fa734..51d19cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -247,7 +247,7 @@ impl Version { Lua52 => "lua-5.2.4", Lua53 => "lua-5.3.6", Lua54 => "lua-5.4.8", - Lua55 => "lua-5.5.0", + Lua55 => "lua-5.5.1", } } From 84763060d6c47953f6bc1ad4d1e4bcfdec0b29fb Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 5 Aug 2026 22:17:42 +0100 Subject: [PATCH 10/12] Update WASI CI toolchain versions --- .github/actions/setup-deps/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-deps/action.yml b/.github/actions/setup-deps/action.yml index 3ba1379..bfb97ea 100644 --- a/.github/actions/setup-deps/action.yml +++ b/.github/actions/setup-deps/action.yml @@ -9,10 +9,10 @@ inputs: default: latest wasi_sdk: description: 'wasi-sdk version to install' - default: 32 + default: 33 wasmtime: description: 'wasmtime version to install' - default: v43.0.0 + default: v47.0.3 runs: using: composite From dd565864012aace8bedabc25911c6dd5b35552c4 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 5 Aug 2026 22:47:07 +0100 Subject: [PATCH 11/12] Use em++ to link Emscripten targets --- .github/actions/setup-deps/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-deps/action.yml b/.github/actions/setup-deps/action.yml index bfb97ea..8882ea4 100644 --- a/.github/actions/setup-deps/action.yml +++ b/.github/actions/setup-deps/action.yml @@ -71,7 +71,7 @@ runs: echo "CC_wasm32_unknown_emscripten=$EMSDK/upstream/emscripten/emcc" >> $GITHUB_ENV echo "CXX_wasm32_unknown_emscripten=$EMSDK/upstream/emscripten/em++" >> $GITHUB_ENV echo "AR_wasm32_unknown_emscripten=$EMSDK/upstream/emscripten/emar" >> $GITHUB_ENV - echo "CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_LINKER=$EMSDK/upstream/emscripten/emcc" >> $GITHUB_ENV + echo "CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_LINKER=$EMSDK/upstream/emscripten/em++" >> $GITHUB_ENV echo "CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER=$EMSDK_NODE" >> $GITHUB_ENV shell: bash From 1664c63c6ed7f430ab475af37f669a2402e0bbbe Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 5 Aug 2026 22:18:06 +0100 Subject: [PATCH 12/12] v551.0.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8219a7d..5a57678 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lua-src" -version = "550.1.1" +version = "551.0.0" authors = ["Aleksandr Orlenko "] edition = "2024" repository = "https://github.com/mlua-rs/lua-src-rs"