mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-04-11 19:16:04 +00:00
25 lines
637 B
Lua
25 lines
637 B
Lua
|
local ffi = require('ffi')
|
||
|
|
||
|
local ext
|
||
|
|
||
|
if ffi.os == 'Linux' then
|
||
|
ext = 'so'
|
||
|
else
|
||
|
ext = 'dylib'
|
||
|
end
|
||
|
|
||
|
ffi.cdef[[
|
||
|
const char* ffi_select(const char *json_str, const char *path);
|
||
|
void *ffi_path_compile(const char *path);
|
||
|
const char* ffi_select_with_compiled(void *ptr, const char *json_str);
|
||
|
]]
|
||
|
|
||
|
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)
|
||
|
return ffi.string(jsonpath.ffi_select_with_compiled(compiledPath, jsonStr));
|
||
|
end
|
||
|
end
|