Created
November 14, 2009 21:53
-
-
Save jcromartie/234803 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)forwardInvocation:(NSInvocation *)anInvocation { | |
lua_State *L = vm.L; | |
lua_rawgeti(L, LUA_REGISTRYINDEX, mappingRef); | |
const char *selStr = [NSStringFromSelector([anInvocation selector]) UTF8String]; | |
// NSLog(@"trying to invoke %s", selStr); | |
lua_getfield(L, -1, selStr); | |
if (!lua_isfunction(L, -1)) { | |
NSLog(@"forwarding %s to %@", selStr, obj); | |
[anInvocation invokeWithTarget:obj]; | |
return; | |
} | |
// we should now have the function on top... let's push the args | |
// set argument values from Lua stack | |
NSMethodSignature *sig = [anInvocation methodSignature]; | |
int luaArgs = [sig numberOfArguments] - 2; | |
for (int ii = 2; ii < [sig numberOfArguments]; ii++) { | |
lmo_pusharg(L, anInvocation, ii); | |
} | |
NSLog(@"doing Lua method"); | |
if (lua_pcall(L, luaArgs, 1, 0)) { | |
const char *s = lua_tostring(L, -1); | |
luaL_error(L, "Error in forwardInvocation: %s", s); | |
return; | |
} | |
void *retPtr; | |
if (lmo_getobjcval(L, &retPtr, [[anInvocation methodSignature] methodReturnType], lua_gettop(L))) { | |
[anInvocation setReturnValue:retPtr]; | |
free(retPtr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment