summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2011-11-18 09:59:39 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2011-11-18 09:59:39 +0100
commita4afecaeb9414535a4da21853c1de01c6d302728 (patch)
tree938c802544af02695cdfc3204bba053ee3b80cad
parent1019f4b28b768085db2f78dac2a3d2f54a8e541f (diff)
downloadlua-file-magic-a4afecaeb9414535a4da21853c1de01c6d302728.tar.bz2
lua-file-magic-a4afecaeb9414535a4da21853c1de01c6d302728.tar.xz
Implement magic_descriptor()
-rw-r--r--magic.c10
-rw-r--r--test.lua18
2 files changed, 23 insertions, 5 deletions
diff --git a/magic.c b/magic.c
index 7697773..2078717 100644
--- a/magic.c
+++ b/magic.c
@@ -151,12 +151,20 @@ static int Psetflags(lua_State *L)
}
}
+static int Pdescriptor(lua_State *L)
+{
+ magic_t m = Pmagic_checkarg(L, 1);
+ int fd = luaL_checknumber(L, 2);
+ lua_pushstring(L, magic_descriptor(m, fd));
+ return 1;
+}
+
static const luaL_reg Pmagic_methods[] = {
{"open", Popen},
{"close", Pclose},
{"getpath", Ptodo},
{"file", Pfile},
- {"descriptor", Ptodo},
+ {"descriptor", Pdescriptor},
{"buffer", Ptodo},
{"error", Perror},
{"setflags", Psetflags},
diff --git a/test.lua b/test.lua
index 83331a7..32bfb57 100644
--- a/test.lua
+++ b/test.lua
@@ -2,15 +2,25 @@
magic = require("magic")
+
m = magic.open()
-
assert(m:load())
-
print(m:errno())
-print(m:file("Makefile"))
+-- test magic.descriptor() from stdin
+if arg[1] == "--stdin" then
+ -- stdin = 0
+ m:setflags(magic.MIME_ENCODING)
+ print(m:descriptor(0))
+ os.exit(0)
+else
+ os.execute("lua test.lua --stdin < Makefile")
+end
+
+print(m:file("Makefile"))
m:setflags(magic.MIME_TYPE)
print(m:error())
-
print(m:file("Makefile"))
+
+