Skip to content

Commit

Permalink
new utility function: luaL_getlstrfield
Browse files Browse the repository at this point in the history
  • Loading branch information
juergen committed Jul 27, 2007
1 parent 37a75a7 commit 526189d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Lua-utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const char* luaL_getstrfield(lua_State* L, const char* key) {
return val;
}

const char* luaL_getlstrfield(lua_State* L, const char* key, int *len) {
const char *val;
lua_getfield(L, -1, key);
val = lua_isnil(L, -1)? NULL : lua_tolstring(L, -1, len);
lua_pop(L, 1);
return val;
}

void _stackDump (lua_State *L, const char *file, int line) {
int i;
int top = lua_gettop(L);
Expand Down
1 change: 1 addition & 0 deletions src/Lua-utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define luaL_checktable(L, n) luaL_checktype(L, n, LUA_TTABLE)
/* return NULL if key doesnt exist */
const char* luaL_getstrfield(lua_State* L, const char* key);
const char* luaL_getlstrfield(lua_State* L, const char* key, int *len);

#define stackDump(L) _stackDump(L, __FILE__, __LINE__)
void _stackDump (lua_State *L, const char* file, int line);
Expand Down

0 comments on commit 526189d

Please sign in to comment.