在3.10的LuaObjcBridge::callObjcStaticMethod有一段代码if (returnLength > 0)
{
if (strcmp(returnType, “@”) == 0)
{
id ret;
[invocation getReturnValue:&ret];
pushValue(L, ret);
}
else if (strcmp(returnType, “c”) == 0) // BOOL
{
char ret;
[invocation getReturnValue:&ret];
lua_pushboolean(L, ret);
}
else if (strcmp(returnType, “i”) == 0) // int
{
int ret;
[invocation getReturnValue:&ret];
lua_pushinteger(L, ret);
}
else if (strcmp(returnType, “f”) == 0) // float
{
float ret;
[invocation getReturnValue:&ret];
lua_pushnumber(L, ret);
}
else
{
NSLog(@“not support return type = %s”, returnType);
lua_pushnil(L);
}
}
根据这段代码的意思,我们把被调用的OC代码中,所有返回值为BOOL的改为了char。lua调用OC的代码正常工作。然而在3.17版本中,这段代码又被改成了
if (returnLength > 0)
{
if (strcmp(returnType, @encode(id)) == 0)
{
id ret;
[invocation getReturnValue:&ret];
pushValue(L, ret);
}
else if (strcmp(returnType, @encode(BOOL)) == 0) // BOOL
{
char ret;
[invocation getReturnValue:&ret];
lua_pushboolean(L, ret);
}
else if (strcmp(returnType, @encode(int)) == 0) // int
{
int ret;
[invocation getReturnValue:&ret];
lua_pushinteger(L, ret);
}
else if (strcmp(returnType, @encode(float)) == 0) // float
{
float ret;
[invocation getReturnValue:&ret];
lua_pushnumber(L, ret);
}
else
{
NSLog(@“not support return type = %s”, returnType);
lua_pushnil(L);
}
}
致使3.10能正常工作的代码在3.17上又无法正常工作了。
为何不多写一句
else if (strcmp(returnType, @encode(char)) == 0) // BOOL
{
char ret;
[invocation getReturnValue:&ret];
lua_pushboolean(L, ret);
}
呢。