diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2011-11-18 09:20:44 +0100 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2011-11-18 09:20:44 +0100 |
commit | 59efa32c03fd650a3f3a3a0e92518224f7833ebf (patch) | |
tree | c077c41d23544c88bb4708704926b95a493aab35 | |
parent | f560a950374635c3cc4a9856234b94e0d19ceff8 (diff) | |
download | lua-file-magic-59efa32c03fd650a3f3a3a0e92518224f7833ebf.tar.bz2 lua-file-magic-59efa32c03fd650a3f3a3a0e92518224f7833ebf.tar.xz |
Implement magic_setflags, fix compiler warning
From Jeff Pohlmeyer
-rw-r--r-- | magic.c | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -115,9 +115,29 @@ static int Perror(lua_State *L) static int Pload(lua_State *L) { magic_t m = Pmagic_checkarg(L, 1); - char *filename = luaL_optstring(L, 2, NULL); - lua_pushstring(L, magic_load(m, filename)); - return 1; + const char *filename = luaL_optstring(L, 2, NULL); + if (magic_load(m, filename)==0) { + lua_pushboolean(L,1); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, magic_error(m)); + return 2; + } +} + +static int Psetflags(lua_State *L) +{ + magic_t m = Pmagic_checkarg(L, 1); + int flags = luaL_checknumber(L, 2); + if (magic_setflags(m, flags)) { + lua_pushboolean(L,1); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, magic_error(m)); + return 2; + } } static const luaL_reg Pmagic_methods[] = { @@ -128,7 +148,7 @@ static const luaL_reg Pmagic_methods[] = { {"descriptor", Ptodo}, {"buffer", Ptodo}, {"error", Perror}, - {"setflags", Ptodo}, + {"setflags", Psetflags}, {"load", Pload}, {"compile", Ptodo}, {"check", Ptodo}, |