Profile Picture

MeForgotPasswrd

Reputation: 0 [rate]

Joined: Apr, 2023

Last online:

Badges

badge

Etc

Send Message

Threads List
Possible Alts

Activity Feed

Replied to thread : since this forums is sh*t dead, im simplydev


wow

 

Content length must be 10-5000 chars

Created a new thread : newcclosure issue in metamethod hooks


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

Commented to thread : What is the easiest "way of execution" for scripts for a beginner to c++ (lbi, bc, proto)


That's to compile the whole source and experiment with it, what you want are the Ast, Common and Compiler Folders for the Luau Compiler, i recommend looking at sources like Maven or SimpleExecutor as they are easy to understand and should give you a better idea of it.

Replied to thread : What is the easiest "way of execution" for scripts for a beginner to c++ (lbi, bc, proto)


Im not an expert so i might be wrong and if i am please correct me but try starting with simply compiling your scripts using Roblox's open source luau compiler and then loading the bytecode using luau_load or LuaVM::Load ( need to compress it first with this one ) and finally executing it using task defer.

 

Here's the luau repo 

https://github.com/Roblox/luau