jsonpath/lua/lib.lua

25 lines
648 B
Lua
Raw Normal View History

2019-08-23 00:00:01 +09:00
local ffi = require('ffi')
local ext
if ffi.os == 'Linux' then
ext = 'so'
else
ext = 'dylib'
end
2019-08-23 11:53:03 +09:00
ffi.cdef [[
2019-08-23 00:00:01 +09:00
const char* ffi_select(const char *json_str, const char *path);
void *ffi_path_compile(const char *path);
2019-08-23 11:53:03 +09:00
const char* ffi_select_with_compiled_path(void *ptr, const char *json_str);
2019-08-23 00:00:01 +09:00
]]
local jsonpathLibPath = os.getenv("JSONPATH_LIB_PATH");
local jsonpath = ffi.load(jsonpathLibPath .. '/libjsonpath_lib.' .. ext);
function compile(path)
local compiledPath = jsonpath.ffi_path_compile(path);
return function(jsonStr)
2019-08-23 11:53:03 +09:00
return ffi.string(jsonpath.ffi_select_with_compiled_path(compiledPath, jsonStr));
2019-08-23 00:00:01 +09:00
end
end