Categories > Coding > C++ >

newcclosure issue in metamethod hooks

Posts: 5

Threads: 1

Joined: Apr, 2023

Reputation: 0

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;
}
  • 0

yranxzy

joe22

vip

Posts: 552

Threads: 113

Joined: Aug, 2020

Reputation: 33

Replied

uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

  • 0

when the function got hennessey

icedmilke222

Squidward

Posts: 53

Threads: 15

Joined: May, 2022

Reputation: 2

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

  • 0

what sup

i lo re c++

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )