Skip to content

类型签名映射表

Karosli edited this page Mar 30, 2022 · 1 revision

类型签名

类型签名表

Objc-C类型 符号
NSString*,NSNumber*,NSObjec*... id
Block ?
NSInteger NSInteger
CGFloat CGFloat
CGSize CGSize
CGRect CGRect
CGPoint CGPoint
CGVector CGVector
NSRange NSRange
Class Class
SEL SEL
BOOL BOOL
void* void*
void void
char* char*
char char
bool bool
float float
double double
short short
int int
long long
long long long long
unsigned short unsigned short
unsigned int unsigned int
unsigned long unsigned long
unsigned long long unsigned long long
size_t size_t

使用场景

1、定义协议

-- lua
-- 定义协议,用于给新增的方法添加方法签名
kkp_protocol("KKPNewClassProtocol", {
    refreshView = "NSString*,void",
},{
    refreshData_ = "NSDictionary*,NSDictionary*"
})
kkp_class({"KKPNewClass", "NSObject", protocols={"KKPNewClassProtocol"}},
function(_ENV)
    function refreshView()
        return "有事"
    end
end,
function(_ENV)
    function refreshData_(data)
        data.thingName = "有事"
        return data
    end
end)

2、定义结构体

// OC
typedef struct XPoint {
    float x;
    float y;
} XPoint;

typedef struct XRect {
    XPoint origin;
    float width;
    float height;
} XRect;

-- lua
-- 注册原生结构体,方便 lua 可以访问结构体数据
kkp_struct({name = "XRect", types = "float,float,float,float", keys = "x,y,width,height"})
kkp_class({"KKPConvertTest"},
function(_ENV)
    function argInXRect_(a)
        a.x = 10.0
        self:setVXRect_(a)
        return a
    end
end)

3、定义 block

// OC
@interface KKPBlockDefineTest : NSObject
@property (nonatomic) int vInt;
@end
@implementation KKPBlockDefineTest

- (void(^)(int))blkVoidOne
{
    return nil;
}

@end
-- lua
kkp_class({"KKPBlockDefineTest"},
function(_ENV)
    function blkVoidOne()
        -- 定义了一个 block,返回值值空,入参是 int 型
        return kkp_block(function(i)
                            self:setVInt_(i)
                        end, "void,int")
    end
end)
Clone this wiki locally