diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lua/luadyncall/src/ldyntype.c	Thu Mar 19 22:26:28 2015 +0100
@@ -0,0 +1,64 @@
+#include "lua.h"
+#include "lauxlib.h"
+#include "dyncall.h"
+#include "dyncall_signature.h"
+
+size_t dtSize(const char* signature)
+{
+  char ch = *signature;
+  switch(ch)
+  {
+    case DC_SIGCHAR_BOOL: return sizeof(DCbool);
+    case DC_SIGCHAR_CHAR: return sizeof(DCchar);
+    case DC_SIGCHAR_UCHAR: return sizeof(DCuchar);
+    case DC_SIGCHAR_SHORT: return sizeof(DCshort);
+    case DC_SIGCHAR_USHORT: return sizeof(DCushort);
+    case DC_SIGCHAR_INT: return sizeof(DCint);
+    case DC_SIGCHAR_UINT: return sizeof(DCuint);
+    case DC_SIGCHAR_LONG: return sizeof(DClong);
+    case DC_SIGCHAR_ULONG: return sizeof(DCulong);
+    case DC_SIGCHAR_LONGLONG: return sizeof(DClonglong);
+    case DC_SIGCHAR_ULONGLONG: return sizeof(DCulonglong);
+    case DC_SIGCHAR_FLOAT: return sizeof(DCfloat);
+    case DC_SIGCHAR_DOUBLE: return sizeof(DCdouble);
+    case DC_SIGCHAR_POINTER: return sizeof(DCpointer);
+    case DC_SIGCHAR_STRING: return sizeof(DCstring);
+    case DC_SIGCHAR_VOID: return sizeof(DCvoid);
+    default: return 0;
+  }
+}
+
+size_t dtAlign(const char* signature)
+{
+  return dtSize(signature);
+}
+
+
+int lua_dtSize(lua_State *L)
+{ 
+  const char* signature = luaL_checkstring(L, 1);
+  lua_pushinteger(L, dtSize(signature));
+  return 1;
+}
+
+int lua_dtAlign(lua_State *L)
+{ 
+  const char* signature = luaL_checkstring(L, 1);
+  lua_pushinteger(L, dtAlign(signature));
+  return 1;
+}
+
+
+static const struct luaL_Reg luareg_ldyntype[] =
+{
+  { "dtSize", lua_dtSize },
+  { "dtAlign", lua_dtAlign },
+  { NULL, NULL }
+};
+
+LUA_API int luaopen_ldyntype(lua_State *L)
+{
+  luaL_register(L, "ldyntype", luareg_ldyntype);
+  return 1;
+}
+