MCPcopy Create free account
hub / github.com/WilliamLCobb/iNDS / DeferFunctionCall

Function DeferFunctionCall

desmume/src/lua-engine.cpp:730–762  ·  view source on GitHub ↗

store the most recent C function call from Lua (and all its arguments) for later evaluation

Source from the content-addressed store, hash-verified

728// store the most recent C function call from Lua (and all its arguments)
729// for later evaluation
730void DeferFunctionCall(lua_State* L, const char* idstring)
731{
732 LuaContextInfo& info = GetCurrentInfo();
733 if(info.numDeferredFuncs < MAX_DEFERRED_COUNT)
734 info.numDeferredFuncs++;
735 else
736 return; // too many deferred functions on the same frame, silently discard the rest
737
738 // there might be a cleaner way of doing this using lua_pushcclosure and lua_getref
739
740 int num = lua_gettop(L);
741
742 // get the C function pointer
743 //lua_CFunction cf = lua_tocfunction(L, -(num+1));
744 lua_CFunction cf = (L->ci->func)->value.gc->cl.c.f;
745 assert(cf);
746 lua_pushcfunction(L,cf);
747
748 // make a list of the function and its arguments (and also pop those arguments from the stack)
749 lua_createtable(L, num+1, 0);
750 lua_insert(L, 1);
751 for(int n = num+1; n > 0; n--)
752 lua_rawseti(L, 1, n);
753
754 // put the list into a global array
755 lua_getfield(L, LUA_REGISTRYINDEX, idstring);
756 lua_insert(L, 1);
757 int curSize = lua_objlen(L, 1);
758 lua_rawseti(L, 1, curSize+1);
759
760 // clean the stack
761 lua_settop(L, 0);
762}
763
764static const char* refStashString = "refstash";
765

Callers 2

DeferGUIFuncIfNeededFunction · 0.85
lua-engine.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected