aboutsummaryrefslogtreecommitdiff
path: root/src/lua/lbaselib.c
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-03-03 21:31:01 +0800
committerLi Jin <dragon-fly@qq.com>2021-03-03 21:33:37 +0800
commit1df786307c1983b8ce693e3916081a8bcd4e95ae (patch)
tree6c7aeb2198d825877fd3d179c394b7a5c1f06a17 /src/lua/lbaselib.c
parent66168b112b707172b9035edf8c1daed469781e06 (diff)
downloadyuescript-1df786307c1983b8ce693e3916081a8bcd4e95ae.tar.gz
yuescript-1df786307c1983b8ce693e3916081a8bcd4e95ae.tar.bz2
yuescript-1df786307c1983b8ce693e3916081a8bcd4e95ae.zip
add new metatable syntax for issue #41, fix reusing local variable issue, update built-in Lua.
Diffstat (limited to 'src/lua/lbaselib.c')
-rw-r--r--src/lua/lbaselib.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/lua/lbaselib.c b/src/lua/lbaselib.c
index 747fd45..83ad306 100644
--- a/src/lua/lbaselib.c
+++ b/src/lua/lbaselib.c
@@ -138,7 +138,7 @@ static int luaB_setmetatable (lua_State *L) {
138 int t = lua_type(L, 2); 138 int t = lua_type(L, 2);
139 luaL_checktype(L, 1, LUA_TTABLE); 139 luaL_checktype(L, 1, LUA_TTABLE);
140 luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table"); 140 luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table");
141 if (luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL) 141 if (l_unlikely(luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL))
142 return luaL_error(L, "cannot change a protected metatable"); 142 return luaL_error(L, "cannot change a protected metatable");
143 lua_settop(L, 2); 143 lua_settop(L, 2);
144 lua_setmetatable(L, 1); 144 lua_setmetatable(L, 1);
@@ -182,7 +182,8 @@ static int luaB_rawset (lua_State *L) {
182 182
183 183
184static int pushmode (lua_State *L, int oldmode) { 184static int pushmode (lua_State *L, int oldmode) {
185 lua_pushstring(L, (oldmode == LUA_GCINC) ? "incremental" : "generational"); 185 lua_pushstring(L, (oldmode == LUA_GCINC) ? "incremental"
186 : "generational");
186 return 1; 187 return 1;
187} 188}
188 189
@@ -299,7 +300,7 @@ static int luaB_ipairs (lua_State *L) {
299 300
300 301
301static int load_aux (lua_State *L, int status, int envidx) { 302static int load_aux (lua_State *L, int status, int envidx) {
302 if (status == LUA_OK) { 303 if (l_likely(status == LUA_OK)) {
303 if (envidx != 0) { /* 'env' parameter? */ 304 if (envidx != 0) { /* 'env' parameter? */
304 lua_pushvalue(L, envidx); /* environment for loaded function */ 305 lua_pushvalue(L, envidx); /* environment for loaded function */
305 if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */ 306 if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
@@ -355,7 +356,7 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
355 *size = 0; 356 *size = 0;
356 return NULL; 357 return NULL;
357 } 358 }
358 else if (!lua_isstring(L, -1)) 359 else if (l_unlikely(!lua_isstring(L, -1)))
359 luaL_error(L, "reader function must return a string"); 360 luaL_error(L, "reader function must return a string");
360 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */ 361 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
361 return lua_tolstring(L, RESERVEDSLOT, size); 362 return lua_tolstring(L, RESERVEDSLOT, size);
@@ -393,7 +394,7 @@ static int dofilecont (lua_State *L, int d1, lua_KContext d2) {
393static int luaB_dofile (lua_State *L) { 394static int luaB_dofile (lua_State *L) {
394 const char *fname = luaL_optstring(L, 1, NULL); 395 const char *fname = luaL_optstring(L, 1, NULL);
395 lua_settop(L, 1); 396 lua_settop(L, 1);
396 if (luaL_loadfile(L, fname) != LUA_OK) 397 if (l_unlikely(luaL_loadfile(L, fname) != LUA_OK))
397 return lua_error(L); 398 return lua_error(L);
398 lua_callk(L, 0, LUA_MULTRET, 0, dofilecont); 399 lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);
399 return dofilecont(L, 0, 0); 400 return dofilecont(L, 0, 0);
@@ -401,7 +402,7 @@ static int luaB_dofile (lua_State *L) {
401 402
402 403
403static int luaB_assert (lua_State *L) { 404static int luaB_assert (lua_State *L) {
404 if (lua_toboolean(L, 1)) /* condition is true? */ 405 if (l_likely(lua_toboolean(L, 1))) /* condition is true? */
405 return lua_gettop(L); /* return all arguments */ 406 return lua_gettop(L); /* return all arguments */
406 else { /* error */ 407 else { /* error */
407 luaL_checkany(L, 1); /* there must be a condition */ 408 luaL_checkany(L, 1); /* there must be a condition */
@@ -437,7 +438,7 @@ static int luaB_select (lua_State *L) {
437** ignored). 438** ignored).
438*/ 439*/
439static int finishpcall (lua_State *L, int status, lua_KContext extra) { 440static int finishpcall (lua_State *L, int status, lua_KContext extra) {
440 if (status != LUA_OK && status != LUA_YIELD) { /* error? */ 441 if (l_unlikely(status != LUA_OK && status != LUA_YIELD)) { /* error? */
441 lua_pushboolean(L, 0); /* first result (false) */ 442 lua_pushboolean(L, 0); /* first result (false) */
442 lua_pushvalue(L, -2); /* error message */ 443 lua_pushvalue(L, -2); /* error message */
443 return 2; /* return false, msg */ 444 return 2; /* return false, msg */