setmetatable raise error

This commit is contained in:
Cloud Wu
2019-04-18 19:17:49 +08:00
committed by 云风
parent 3a0981661c
commit e3c5d63a97

View File

@@ -858,6 +858,8 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
}
switch (ttnov(obj)) {
case LUA_TTABLE: {
if (isshared(hvalue(obj)))
luaG_runerror(L, "can't setmetatable to shared table");
hvalue(obj)->metatable = mt;
if (mt) {
luaC_objbarrier(L, gcvalue(obj), mt);
@@ -1041,10 +1043,8 @@ LUA_API void lua_clonefunction (lua_State *L, const void * fp) {
}
LUA_API void lua_sharefunction (lua_State *L, int index) {
if (!lua_isfunction(L,index) || lua_iscfunction(L,index)) {
lua_pushstring(L, "Only Lua function can share");
lua_error(L);
}
if (!lua_isfunction(L,index) || lua_iscfunction(L,index))
luaG_runerror(L, "Only Lua function can share");
LClosure *f = cast(LClosure *, lua_topointer(L, index));
luaF_shareproto(f->p);
}