Permalink
Browse files

new utility function: luaL_getlstrfield

  • Loading branch information...
1 parent 37a75a7 commit 526189d521c0f56961e9d8647a6808a71eb6fe4a juergen committed Jul 27, 2007
Showing with 9 additions and 0 deletions.
  1. +8 −0 src/Lua-utility.c
  2. +1 −0 src/Lua-utility.h
View
@@ -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);
View
@@ -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);

0 comments on commit 526189d

Please sign in to comment.