summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--magic.c11
-rw-r--r--test.lua2
2 files changed, 12 insertions, 1 deletions
diff --git a/magic.c b/magic.c
index 2078717..d138302 100644
--- a/magic.c
+++ b/magic.c
@@ -159,13 +159,22 @@ static int Pdescriptor(lua_State *L)
return 1;
}
+static int Pbuffer(lua_State *L)
+{
+ size_t size;
+ magic_t m = Pmagic_checkarg(L, 1);
+ const char *buf = luaL_checklstring(L, 2, &size);
+ lua_pushstring(L, magic_buffer(m, buf, size));
+ return 1;
+}
+
static const luaL_reg Pmagic_methods[] = {
{"open", Popen},
{"close", Pclose},
{"getpath", Ptodo},
{"file", Pfile},
{"descriptor", Pdescriptor},
- {"buffer", Ptodo},
+ {"buffer", Pbuffer},
{"error", Perror},
{"setflags", Psetflags},
{"load", Pload},
diff --git a/test.lua b/test.lua
index 32bfb57..7ac6e67 100644
--- a/test.lua
+++ b/test.lua
@@ -22,5 +22,7 @@ m:setflags(magic.MIME_TYPE)
print(m:error())
print(m:file("Makefile"))
+m:setflags(magic.NONE)
+print(m:buffer("#!/bin/bash\n"))