Пример #1
0
static void full_tofunc(lua_State *L, luaA_Type type_id, void *cout, int index)
{
  if(!dt_lua_isa_type(L,index,type_id)) {
    char error_msg[256];
    snprintf(error_msg,sizeof(error_msg),"%s expected",luaA_typename(L,type_id));
    luaL_argerror(L,index,error_msg);
  } 
  void* udata = lua_touserdata(L,index);
  memcpy(cout, udata, luaA_typesize(L, type_id));
}
Пример #2
0
GList *dt_lua_to_glist_type(lua_State *L, luaA_Type elt_type, int index)
{
  // recreate list of images
  GList *list = NULL;
  size_t type_size = luaA_typesize(L, elt_type);
  lua_pushnil(L); /* first key */
  while(lua_next(L, index - 1) != 0)
  {
    /* uses 'key' (at index -2) and 'value' (at index -1) */
    void *obj = malloc(type_size);
    luaA_to_type(L, elt_type, obj, -1);
    lua_pop(L, 1);
    list = g_list_prepend(list, (gpointer)obj);
  }
  list = g_list_reverse(list);
  return list;
}
Пример #3
0
static int full_pushfunc(lua_State *L, luaA_Type type_id, const void *cin)
{
  size_t type_size = luaA_typesize(L, type_id);
  void *udata = lua_newuserdata(L, type_size);
  lua_newtable(L);
  lua_setuservalue(L, -2);
  if(cin)
  {
    memcpy(udata, cin, type_size);
  }
  else
  {
    memset(udata, 0, type_size);
  }
  luaL_setmetatable(L, luaA_typename(L, type_id));

  if(luaL_getmetafield(L, -1, "__init"))
  {
    lua_pushvalue(L, -2);                  // the new alocated object
    lua_pushlightuserdata(L, (void *)cin); // forced to cast..
    lua_call(L, 2, 0);
  }
  return 1;
}