aboutsummaryrefslogtreecommitdiff
path: root/tests/encode.lua
blob: e8026cc3f92d0ba2b0a4c958f98325270af85d3b (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
#!/usr/bin/env 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

if not arg[1] then
    print("usage: encode.lua FILE")
    os.exit(-1)
end

print(cjson.encode(get_lua_table(arg[1])))

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