store the most recent C function call from Lua (and all its arguments) for later evaluation
| 728 | // store the most recent C function call from Lua (and all its arguments) |
| 729 | // for later evaluation |
| 730 | void 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 | |
| 764 | static const char* refStashString = "refstash"; |
| 765 |
no outgoing calls
no test coverage detected