diff options
Diffstat (limited to 'tests/encode.lua')
| -rwxr-xr-x | tests/encode.lua | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/tests/encode.lua b/tests/encode.lua deleted file mode 100755 index 6b767cb..0000000 --- a/tests/encode.lua +++ /dev/null | |||
| @@ -1,28 +0,0 @@ | |||
| 1 | #!/usr/bin/env lua | ||
| 2 | |||
| 3 | -- usage: encode.lua [lua_file] | ||
| 4 | -- | ||
| 5 | -- Eg: | ||
| 6 | -- echo '{ "testing" }' | ./encode.lua | ||
| 7 | -- ./encode.lua lua_data.lua | ||
| 8 | |||
| 9 | local json = require "cjson" | ||
| 10 | local misc = require "cjson-misc" | ||
| 11 | |||
| 12 | function get_lua_table(file) | ||
| 13 | local func = loadstring("data = " .. misc.file_load(file)) | ||
| 14 | if func == nil then | ||
| 15 | error("Invalid syntax? Lua table required.") | ||
| 16 | end | ||
| 17 | |||
| 18 | local env = {} | ||
| 19 | func = setfenv(func, env) | ||
| 20 | func() | ||
| 21 | |||
| 22 | return env.data | ||
| 23 | end | ||
| 24 | |||
| 25 | local t = get_lua_table(arg[1]) | ||
| 26 | print(json.encode(t)) | ||
| 27 | |||
| 28 | -- vi:ai et sw=4 ts=4: | ||
