From 516601cb8e909d4c32ef50b10d34e4dd0b467b46 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Tue, 2 Feb 2016 17:19:46 +0000 Subject: MirLua: libjson-based json parser git-svn-id: http://svn.miranda-ng.org/main/trunk@16215 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/Modules/JSON/src/json.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 plugins/MirLua/Modules/JSON/src/json.cpp (limited to 'plugins/MirLua/Modules/JSON/src/json.cpp') 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 -- cgit v1.2.3