diff options
author | Mark Pulford <mark@kyne.com.au> | 2011-05-16 19:46:05 +0930 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2011-05-16 19:46:05 +0930 |
commit | 6ba7499ac5992c8cc849ffcbd6d2837d305f5b63 (patch) | |
tree | f7765d77bb51d3401f4fe0a9acc7279596928918 /tests/encode.lua | |
parent | 22550d0ab3328554922822ca0207996b3d1bb73e (diff) | |
download | lua-cjson-6ba7499ac5992c8cc849ffcbd6d2837d305f5b63.tar.gz lua-cjson-6ba7499ac5992c8cc849ffcbd6d2837d305f5b63.tar.bz2 lua-cjson-6ba7499ac5992c8cc849ffcbd6d2837d305f5b63.zip |
Add support for stdin to encode.lua/decode.lua
Diffstat (limited to 'tests/encode.lua')
-rwxr-xr-x | tests/encode.lua | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/tests/encode.lua b/tests/encode.lua index e8026cc..f13787c 100755 --- a/tests/encode.lua +++ b/tests/encode.lua | |||
@@ -1,5 +1,11 @@ | |||
1 | #!/usr/bin/env lua | 1 | #!/usr/bin/env lua |
2 | 2 | ||
3 | -- usage: encode.lua [lua_file] | ||
4 | -- | ||
5 | -- Eg: | ||
6 | -- echo '{ "testing" }' | ./encode.lua | ||
7 | -- ./encode.lua lua_data.lua | ||
8 | |||
3 | require "common" | 9 | require "common" |
4 | require "cjson" | 10 | require "cjson" |
5 | 11 | ||
@@ -16,11 +22,7 @@ function get_lua_table(file) | |||
16 | return env.data | 22 | return env.data |
17 | end | 23 | end |
18 | 24 | ||
19 | if not arg[1] then | 25 | local t = get_lua_table(arg[1]) |
20 | print("usage: encode.lua FILE") | 26 | print(cjson.encode(t)) |
21 | os.exit(-1) | ||
22 | end | ||
23 | |||
24 | print(cjson.encode(get_lua_table(arg[1]))) | ||
25 | 27 | ||
26 | -- vi:ai et sw=4 ts=4: | 28 | -- vi:ai et sw=4 ts=4: |