lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

struct.c from alien (maybe the original struct lib too) line 83 should be

case 'i': case 'I': return getnum(fmt, sizeof(int));

instead of

case 'i': return getnum(fmt, sizeof(int));

.. and since I'm spamming the list with small potatoes, I also made a
handy memcpy() for alien to copy strings and userdata into buffers
directly.

static int alien_memcpy(lua_State *L) {
  void* dst;
  void* src;
  size_t size;
  dst = lua_touserdata(L, 1);
  if (!dst)
    luaL_typerror(L, 1, "userdata or light userdata");
  if (!(lua_isuserdata(L, 2) || lua_isstring(L, 2)))
    luaL_typerror(L, 2, "string, userdata, or light userdata");
  if (lua_isuserdata(L, 2)) {
    src = lua_touserdata(L, 2);
    size = luaL_checkint(L, 3);
  }
  else {
    src = (void*)lua_tolstring(L, 2, &size);
    size = luaL_optint(L, 3, size);
  }
  if (size > 0)
    memcpy(dst, src, size);
  return 1;
}