summaryrefslogtreecommitdiff
path: root/tests/encode.lua
blob: f13787c5a0e8ae6bd433861fb0f81294432e9d58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env lua

-- usage: encode.lua [lua_file]
--
-- Eg:
-- echo '{ "testing" }' | ./encode.lua
-- ./encode.lua lua_data.lua

require "common"
require "cjson"

function get_lua_table(file)
	local func = loadstring("data = " .. file_load(file))
	if func == nil then
		error("Invalid syntax? Lua table required.")
	end

	local env = {}
	func = setfenv(func, env)
	func()

	return env.data
end

local t = get_lua_table(arg[1])
print(cjson.encode(t))

-- vi:ai et sw=4 ts=4: