int luax_convobj(lua_State *L, int idxs[], int n, const char *mod, const char *fn) { luax_getfunction(L, mod, fn); for (int i = 0; i < n; i++) { lua_pushvalue(L, idxs[i]); // The arguments. } lua_call(L, n, 2); // Call the function, n args, one return value (plus optional errstring.) luax_assert_nilerror(L, -2); // Make sure the function returned something. lua_pop(L, 1); // Pop the second return value now that we don't need it. lua_replace(L, idxs[0]); // Replace the initial argument with the new object. return 0; }
int luax_convobj(lua_State *L, int idx, const char *mod, const char *fn) { // Convert to absolute index if necessary. if (idx < 0 && idx > LUA_REGISTRYINDEX) idx += lua_gettop(L) + 1; // Convert string to a file. luax_getfunction(L, mod, fn); lua_pushvalue(L, idx); // The initial argument. lua_call(L, 1, 2); // Call the function, one arg, one return value (plus optional errstring.) luax_assert_nilerror(L, -2); // Make sure the function returned something. lua_pop(L, 1); // Pop the second return value now that we don't need it. lua_replace(L, idx); // Replace the initial argument with the new object. return 0; }