summaryrefslogtreecommitdiff
path: root/plugins/MirLua/Modules/JSON/src/json.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirLua/Modules/JSON/src/json.cpp')
-rw-r--r--plugins/MirLua/Modules/JSON/src/json.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/plugins/MirLua/Modules/JSON/src/json.cpp b/plugins/MirLua/Modules/JSON/src/json.cpp
new file mode 100644
index 0000000000..edfa04fb83
--- /dev/null
+++ b/plugins/MirLua/Modules/JSON/src/json.cpp
@@ -0,0 +1,28 @@
+#include "stdafx.h"
+
+static int lua_decode(lua_State *L)
+{
+ const char *string = luaL_checkstring(L, 1);
+ MT *udata = (MT*)lua_newuserdata(L, sizeof(MT));
+ udata->node = json_parse(string);
+ udata->bDelete = true;
+ luaL_setmetatable(L, MT_JSON);
+ return 1;
+}
+
+static const luaL_Reg methods[] =
+{
+ { "decode", lua_decode },
+ { NULL, NULL }
+};
+
+LUA_LIBRARY_EXPORT(json)
+{
+ luaL_newlib(L, methods);
+
+ luaL_newmetatable(L, MT_JSON);
+ luaL_setfuncs(L, jsonApi, 0);
+ lua_pop(L, 1);
+
+ return 1;
+} \ No newline at end of file