summaryrefslogtreecommitdiff
path: root/plugins/MirLua/Modules/m_json/src/main.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2016-06-19 18:42:13 +0000
committerAlexander Lantsev <aunsane@gmail.com>2016-06-19 18:42:13 +0000
commit1b6c4e6e4a16ed49570e1787641e5af79dba23f7 (patch)
tree620245ae2a5ded115b26f79a6f422881a9340365 /plugins/MirLua/Modules/m_json/src/main.cpp
parent6593f9613819dbc42ffff76a4d7a6d5156b46eae (diff)
MirLua: almost work m_json
git-svn-id: http://svn.miranda-ng.org/main/trunk@17013 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/Modules/m_json/src/main.cpp')
-rw-r--r--plugins/MirLua/Modules/m_json/src/main.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/MirLua/Modules/m_json/src/main.cpp b/plugins/MirLua/Modules/m_json/src/main.cpp
new file mode 100644
index 0000000000..fe987d36f3
--- /dev/null
+++ b/plugins/MirLua/Modules/m_json/src/main.cpp
@@ -0,0 +1,48 @@
+#include "stdafx.h"
+
+static int lua_Decode(lua_State *L)
+{
+ const char *string = luaL_checkstring(L, 1);
+
+ JSONNode *node = json_parse(string);
+ new (L) JSON(node);
+ luaL_setmetatable(L, MT_JSON);
+
+ return 1;
+}
+
+static int lua_Encode(lua_State *L)
+{
+ luaL_checktype(L, 1, LUA_TTABLE);
+
+ JSONNode *node = json_new(JSON_NODE);
+ lua_pushnil(L);
+ while (lua_next(L, 1) != 0)
+ {
+ lua2json(L, *node);
+ lua_pop(L, 1);
+ }
+ JSON *mt = new (L) JSON(node);
+ luaL_setmetatable(L, MT_JSON);
+
+ return 1;
+}
+
+static const luaL_Reg methods[] =
+{
+ { "Dcode", lua_Decode },
+ { "Encode", lua_Encode },
+
+ { NULL, NULL }
+};
+
+extern "C" LUAMOD_API int luaopen_m_json(lua_State *L)
+{
+ 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