Skip to content

Commit

Permalink
Exposed, documented, and changed the functionality of -[MLCBridgedObj…
Browse files Browse the repository at this point in the history
…ect forwardInvocation:] to never retrieve values from the table (only ever call functions)
  • Loading branch information
jspahrsummers committed Nov 7, 2011
1 parent 5f8dc9a commit 0771025
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
10 changes: 10 additions & 0 deletions Framework/MoonlitCocoa/MoonlitCocoa/MLCBridgedObject.h
Expand Up @@ -60,6 +60,16 @@
*/
+ (lua_CFunction)eqMetamethod;

/**
* Uses the selector of \a invocation as a key into the Lua table backing the
* receiver, invoking the function associated with that key using the arguments
* from \a invocation (after converting to the appropriate Lua types). If the
* invocation's method signature dictates a return value, the first return value
* from the function is used; zero is returned if the function has no return
* values.
*/
- (void)forwardInvocation:(NSInvocation *)invocation;

/**
* Returns the instance of the receiver corresponding to \a userdata, or \c nil
* if \a userdata is invalid or does not contain an instance of the receiver.
Expand Down
23 changes: 10 additions & 13 deletions Framework/MoonlitCocoa/MoonlitCocoa/MLCBridgedObject.m
Expand Up @@ -315,21 +315,18 @@ - (void)forwardInvocation:(NSInvocation *)invocation {
[[self class] pushUserdataMetatable];
[state popTableAndPushField:selectorName];

if (![state popReturnValueForInvocation:invocation]) {
// push self as first argument
[self pushOntoStack:state];
[state pushArgumentsOfInvocation:invocation];

NSError *error = nil;
if (![state callFunctionWithArgumentCount:argumentCount - 1 resultCount:resultCount error:&error]) {
NSLog(@"Exception occurred when invoking %@ in Lua: %@", selectorName, error);
return NO;
}

if (resultCount)
[state popReturnValueForInvocation:invocation];
// push self as first argument
[self pushOntoStack:state];
[state pushArgumentsOfInvocation:invocation];

NSError *error = nil;
if (![state callFunctionWithArgumentCount:argumentCount - 1 resultCount:resultCount error:&error]) {
NSLog(@"Exception occurred when invoking %@ in Lua: %@", selectorName, error);
return NO;
}

[state popReturnValueForInvocation:invocation];

return YES;
}];
}
Expand Down

0 comments on commit 0771025

Please sign in to comment.