Skip to content

Instantly share code, notes, and snippets.

@arce
Last active December 8, 2019 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arce/096171dd7a6bc2d376c384dd6175037e to your computer and use it in GitHub Desktop.
Save arce/096171dd7a6bc2d376c384dd6175037e to your computer and use it in GitHub Desktop.
dataVector REDIS
//full userdata
extern "C" int newarray(lua_State* L)
{
int n = luaL_checkint(L, 1);
size_t nbytes = sizeof(CharArray) + (n - 1)*sizeof(char);
CharArray* a = (CharArray*)lua_newuserdata(L, nbytes);
a->size = n;
return 1;
}
//light userdata
extern "C" int newlarray(lua_State* L)
{
int n = luaL_checkint(L, 1);
size_t nbytes = sizeof(CharArray) + (n - 1)*sizeof(char);
CharArray* a = (CharArray*)(new char(nbytes));
lua_pushlightuserdata(L,a);
a->size = n;
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment