Skip to content

Instantly share code, notes, and snippets.

@Houdini
Last active August 29, 2015 14:14
Show Gist options
  • Save Houdini/62a1c700861de0e1b8b3 to your computer and use it in GitHub Desktop.
Save Houdini/62a1c700861de0e1b8b3 to your computer and use it in GitHub Desktop.
lua test.lua
lua: test.lua:5: attempt to index a nil value (global 'zstring')
stack traceback:
test.lua:5: in main chunk
[C]: in ?
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include <string.h>
/* gcc zstring.c -Wall -shared -o zstring.so */
static int zst_strlen(lua_State *L)
{
size_t len;
len = strlen(lua_tostring(L, 1));
lua_pushnumber(L, len);
return 1;
}
int luaopen_zstring(lua_State *L)
{
lua_register(L,"zst_strlen", zst_strlen);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment