Beispiel #1
0
void handle_unregisterX(lua::state& L, uint64_t addr, int lfn)
{
    lua_debug_callback_dict* Dx;
    lua_debug_callback2* D = NULL;
    L.pushlightuserdata(&CONST_lua_cb_list_key);
    L.rawget(LUA_REGISTRYINDEX);
    if(!L.isnil(-1)) {
        Dx = (lua_debug_callback_dict*)L.touserdata(-1);
        auto key = std::make_pair(type, addr);
        if(Dx->cblist.count(key))
            D = Dx->cblist[key];
        L.pop(1);
        while(D) {
            if(D->dead || D->type != type || D->addr != addr || L.topointer(lfn) != D->lua_fn) {
                D = D->next;
                continue;
            }
            //Remove this.
            auto Dold = D;
            D = D->next;
            Dold->unregister();
        }
    } else
        L.pop(1);
}
Beispiel #2
0
void lua::RegisterEngine(lua::state &st)
{
	st.getglobal("engine");
	if(st.is<lua::nil>())
	{
		st.pop();
		st.newtable();
	}
	lua::RegFunctionsLocal(st,lua_engine_func);
	st.setglobal("engine");
}
Beispiel #3
0
void lua::RegisterProcess(lua::state &st,DFHack::Process *p)
{
	st.getglobal("Process");
	if(st.is<lua::nil>())
	{
		st.pop();
		st.newtable();
	}

	st.pushlightuserdata(p);
	st.setfield("__pointer");
	
	lua::RegFunctionsLocal(st, lua_process_func);

	st.setglobal("Process");
}
Beispiel #4
0
void handle_registerX(lua::state& L, uint64_t addr, int lfn)
{
    //Put the context in userdata so it can be gc'd when Lua context is terminated.
    lua_debug_callback2* D = (lua_debug_callback2*)L.newuserdata(sizeof(lua_debug_callback2));
    new(D) lua_debug_callback2;
    L.newtable();
    L.pushstring("__gc");
    L.push_trampoline(&lua_debug_callback2::on_lua_gc, 0);
    L.rawset(-3);
    L.setmetatable(-2);
    L.pushlightuserdata(D);
    L.pushvalue(-2);
    L.rawset(LUA_REGISTRYINDEX);
    L.pop(1); //Pop the copy of object.

    D->L = &L.get_master();
    D->addr = addr;
    D->type = type;
    D->dead = false;
    D->set_lua_fn(lfn);
    D->link_to_list();

    CORE().dbg->add_callback(addr, type, *D);
}