Categories > Coding > C++ >
newcclosure issue in metamethod hooks
Posted
Hi, my newcclosure works fine but when used in a metamethod hook it suddenly starts causing a lot of lag and a crash in the game.
I don't know why it happens so I'd appreciate some help.
btw i already confirmed it is newcclosure thanks to some testing.
int newcclosurehandler(lua_State* ls){
auto nargs = lua_gettop(ls);
// we dont wanna copy the args so we insert the func at the top ;
lua_pushvalue(ls, lua_upvalueindex(1));
lua_insert(ls,1);
int status = api::rlua_pcall(ls, nargs, LUA_MULTRET, 0);
if (status && strcmp(lua_tostring(ls,-1), "attempt to yield across metamethod/C-call boundary") == 0) return lua_yield(ls,0);
return lua_gettop(ls); // return all results
}
int newcclosure(lua_State* ls){
luaL_checktype(ls, 1, LUA_TFUNCTION);
if (lua_iscfunction(ls, 1)) {
return 1;
}
lua_pushcclosurek(ls, newcclosurehandler, 0, 1,0);
auto ncl = ((Closure*)lua_topointer(ls, -1));
ExecClosures.insert(ncl);
return 1;
}
Replied
uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Cancel
Post
Replied
u did pcall on roblox's side, n youre trying to retrieve the error string (from roblox) on your side (which wont exist since youre doing pcall on robloxs side), you should instead do all of the newcclosure handling on roblox's side
Cancel
Post
what sup
i lo re c++
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post