commit | author | age
|
6e1425
|
1 |
// |
H |
2 |
// wax_helpers.h |
|
3 |
// Lua |
|
4 |
// |
|
5 |
// Created by ProbablyInteractive on 5/18/09. |
|
6 |
// Copyright 2009 Probably Interactive. All rights reserved. |
|
7 |
// |
|
8 |
|
|
9 |
#import <Foundation/Foundation.h> |
|
10 |
#import <objc/runtime.h> |
|
11 |
#import <objc/message.h> |
|
12 |
|
|
13 |
#import "wax_instance.h" |
|
14 |
|
|
15 |
//#import "lua.h" |
|
16 |
#import <lua/lua.h> |
|
17 |
|
|
18 |
//#define _C_ATOM '%' |
|
19 |
//#define _C_VECTOR '!' |
|
20 |
//#define _C_CONST 'r' |
|
21 |
|
|
22 |
// ENCODINGS CAN BE FOUND AT http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html |
|
23 |
#define WAX_TYPE_CHAR _C_CHR |
|
24 |
#define WAX_TYPE_INT _C_INT |
|
25 |
#define WAX_TYPE_SHORT _C_SHT |
|
26 |
#define WAX_TYPE_UNSIGNED_CHAR _C_UCHR |
|
27 |
#define WAX_TYPE_UNSIGNED_INT _C_UINT |
|
28 |
#define WAX_TYPE_UNSIGNED_SHORT _C_USHT |
|
29 |
|
|
30 |
#define WAX_TYPE_LONG _C_LNG |
|
31 |
#define WAX_TYPE_LONG_LONG _C_LNG_LNG |
|
32 |
#define WAX_TYPE_UNSIGNED_LONG _C_ULNG |
|
33 |
#define WAX_TYPE_UNSIGNED_LONG_LONG _C_ULNG_LNG |
|
34 |
#define WAX_TYPE_FLOAT _C_FLT |
|
35 |
#define WAX_TYPE_DOUBLE _C_DBL |
|
36 |
|
|
37 |
#define WAX_TYPE_C99_BOOL _C_BOOL |
|
38 |
|
|
39 |
#define WAX_TYPE_STRING _C_CHARPTR |
|
40 |
#define WAX_TYPE_VOID _C_VOID |
|
41 |
#define WAX_TYPE_ARRAY _C_ARY_B |
|
42 |
#define WAX_TYPE_ARRAY_END _C_ARY_E |
|
43 |
#define WAX_TYPE_BITFIELD _C_BFLD |
|
44 |
#define WAX_TYPE_ID _C_ID |
|
45 |
#define WAX_TYPE_CLASS _C_CLASS |
|
46 |
#define WAX_TYPE_SELECTOR _C_SEL |
|
47 |
#define WAX_TYPE_STRUCT _C_STRUCT_B |
|
48 |
#define WAX_TYPE_STRUCT_END _C_STRUCT_E |
|
49 |
#define WAX_TYPE_UNION _C_UNION_B |
|
50 |
#define WAX_TYPE_UNION_END _C_UNION_E |
|
51 |
#define WAX_TYPE_POINTER _C_PTR |
|
52 |
#define WAX_TYPE_UNKNOWN _C_UNDEF |
|
53 |
|
|
54 |
#define WAX_PROTOCOL_TYPE_CONST 'r' |
|
55 |
#define WAX_PROTOCOL_TYPE_IN 'n' |
|
56 |
#define WAX_PROTOCOL_TYPE_INOUT 'N' |
|
57 |
#define WAX_PROTOCOL_TYPE_OUT 'o' |
|
58 |
#define WAX_PROTOCOL_TYPE_BYCOPY 'O' |
|
59 |
#define WAX_PROTOCOL_TYPE_BYREF 'R' |
|
60 |
#define WAX_PROTOCOL_TYPE_ONEWAY 'V' |
|
61 |
|
|
62 |
#define BEGIN_STACK_MODIFY(L) int __startStackIndex = lua_gettop((L)); |
|
63 |
|
|
64 |
#define END_STACK_MODIFY(L, i) while(lua_gettop((L)) > (__startStackIndex + (i))) lua_remove((L), __startStackIndex + 1); |
|
65 |
|
|
66 |
#ifndef LOG_FLAGS |
|
67 |
#define LOG_FLAGS (LOG_FATAL | LOG_ERROR | LOG_DEBUG) |
|
68 |
#endif |
|
69 |
|
|
70 |
#define LOG_DEBUG 1 << 0 |
|
71 |
#define LOG_ERROR 1 << 1 |
|
72 |
#define LOG_FATAL 1 << 2 |
|
73 |
|
|
74 |
#define LOG_GC 1 << 5 |
|
75 |
#define LOG_NETWORK 1 << 6 |
|
76 |
|
|
77 |
// Debug Helpers |
|
78 |
void wax_printStack(lua_State *L); |
|
79 |
void wax_printStackAt(lua_State *L, int i); |
|
80 |
void wax_printTable(lua_State *L, int t); |
|
81 |
void wax_log(int flag, NSString *format, ...); |
|
82 |
int wax_getStackTrace(lua_State *L); |
|
83 |
|
|
84 |
// Convertion Helpers |
|
85 |
int wax_fromObjc(lua_State *L, const char *typeDescription, void *buffer); |
|
86 |
void wax_fromInstance(lua_State *L, id instance); |
|
87 |
void wax_fromStruct(lua_State *L, const char *typeDescription, void *buffer); |
|
88 |
|
|
89 |
void *wax_copyToObjc(lua_State *L, const char *typeDescription, int stackIndex, int *outsize); |
|
90 |
|
|
91 |
// Misc Helpers |
|
92 |
void wax_selectorsForName(const char *methodName, SEL selectors[2]); |
|
93 |
BOOL wax_selectorForInstance(wax_instance_userdata *instanceUserdata, SEL* foundSelectors, const char *methodName, BOOL forceInstanceCheck); |
|
94 |
void wax_pushMethodNameFromSelector(lua_State *L, SEL selector); |
|
95 |
BOOL wax_isInitMethod(const char *methodName); |
|
96 |
|
|
97 |
const char *wax_removeProtocolEncodings(const char *type_descriptions); |
|
98 |
|
|
99 |
int wax_sizeOfTypeDescription(const char *full_type_description); |
|
100 |
int wax_simplifyTypeDescription(const char *in, char *out); |
|
101 |
|
|
102 |
int wax_errorFunction(lua_State *L); |
|
103 |
int wax_pcall(lua_State *L, int argumentCount, int returnCount); |