I don't think something like this would work. I'm still not very
familiar with the Lua source code, but what I learnt is that
ultimately (even after trying all metamethods, __call included)
standard Lua would call only call an object of type LUA_TFUNCTION.
Look at this code from ldo.c:
static StkId tryfuncTM (lua_State *L, StkId func) {
const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);
StkId p;
ptrdiff_t funcr = savestack(L, func);
>>>HERE <<< if (!ttisfunction(tm))
luaG_typeerror(L, func, "call");
/* Open a hole inside the stack at `func' */
for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);
incr_top(L);
func = restorestack(L, funcr); /* previous call may change stack */
setobj2s(L, func, tm); /* tag method is the new function to be called
*/
return func;
}
Objects of type LUA_TFUNCTION are allocated in RAM by luaL_register
(via lua_pushcclosure), so you'd still need RAM to call your function,