comparison lua/luadyncall/src/ldyntype.c @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0cfcc391201f
1 #include "lua.h"
2 #include "lauxlib.h"
3 #include "dyncall.h"
4 #include "dyncall_signature.h"
5
6 size_t dtSize(const char* signature)
7 {
8 char ch = *signature;
9 switch(ch)
10 {
11 case DC_SIGCHAR_BOOL: return sizeof(DCbool);
12 case DC_SIGCHAR_CHAR: return sizeof(DCchar);
13 case DC_SIGCHAR_UCHAR: return sizeof(DCuchar);
14 case DC_SIGCHAR_SHORT: return sizeof(DCshort);
15 case DC_SIGCHAR_USHORT: return sizeof(DCushort);
16 case DC_SIGCHAR_INT: return sizeof(DCint);
17 case DC_SIGCHAR_UINT: return sizeof(DCuint);
18 case DC_SIGCHAR_LONG: return sizeof(DClong);
19 case DC_SIGCHAR_ULONG: return sizeof(DCulong);
20 case DC_SIGCHAR_LONGLONG: return sizeof(DClonglong);
21 case DC_SIGCHAR_ULONGLONG: return sizeof(DCulonglong);
22 case DC_SIGCHAR_FLOAT: return sizeof(DCfloat);
23 case DC_SIGCHAR_DOUBLE: return sizeof(DCdouble);
24 case DC_SIGCHAR_POINTER: return sizeof(DCpointer);
25 case DC_SIGCHAR_STRING: return sizeof(DCstring);
26 case DC_SIGCHAR_VOID: return sizeof(DCvoid);
27 default: return 0;
28 }
29 }
30
31 size_t dtAlign(const char* signature)
32 {
33 return dtSize(signature);
34 }
35
36
37 int lua_dtSize(lua_State *L)
38 {
39 const char* signature = luaL_checkstring(L, 1);
40 lua_pushinteger(L, dtSize(signature));
41 return 1;
42 }
43
44 int lua_dtAlign(lua_State *L)
45 {
46 const char* signature = luaL_checkstring(L, 1);
47 lua_pushinteger(L, dtAlign(signature));
48 return 1;
49 }
50
51
52 static const struct luaL_Reg luareg_ldyntype[] =
53 {
54 { "dtSize", lua_dtSize },
55 { "dtAlign", lua_dtAlign },
56 { NULL, NULL }
57 };
58
59 LUA_API int luaopen_ldyntype(lua_State *L)
60 {
61 luaL_register(L, "ldyntype", luareg_ldyntype);
62 return 1;
63 }
64