mongrel2 / Tir

A Simple Lua Web Framework For Mongrel2

Home Page:http://tir.mongrel2.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tir complaining about json

martletandco opened this issue · comments

Going through the Arc Challenge example, after starting Mongrel2, 'tir start' gives:

Started app/arc_challenge.lua PID 6621 lua: /usr/share/lua/5.1//json/util.lua:149: variable 'json' is not declared stack traceback: [C]: in function 'error' /usr/share/lua/5.1//tir/strict.lua:37: in function </usr/share/lua/5.1//tir/strict.lua:35> /usr/share/lua/5.1//json/util.lua:149: in main chunk [C]: in function 'require' /usr/share/lua/5.1//json/decode.lua:10: in main chunk [C]: in function 'require' /usr/share/lua/5.1//json.lua:5: in main chunk [C]: in function 'require' /usr/share/lua/5.1//tir/util.lua:5: in main chunk [C]: in function 'require' /usr/share/lua/5.1//tir/engine.lua:12: in main chunk [C]: in function 'require' app/arc_challenge.lua:1: in main chunk [C]: ? CHILD DIED app/arc_challenge.lua PID 6621: exited SCRIPT app/arc_challenge.lua RESTARTING TOO FAST. Pausing while you fix stuff.

It seems Tir doesn't get anywhere as the traceback shows it chokes after loading a few files.
I'm not sure what is causing the issue as LuaRocks installed json with a problem. The following code runs fine:

require 'json' val = {'A', 'B', 'C'} val_json = json.encode( val ) val_unjson = json.decode( val_json ) print( val_json ) print( val_unjson[1] )

Any help would be fantastic.

I'm having the exact same problem - running Lua 5.1 installed from Homebrew. The source of json/util.lua at that point is

if not is_52 then
    _G.json = _G.json or {}
    _G.json.util = json_util
end

Is it perhaps because of Lua 5.1 vs 5.2? I'm going to try this on another machine and attempt to get 5.2 rolling with it.

The problem is that tir uses "strict" and the following line barfs:

_G.json = _G.json or { }

replace it with:

_G.json = rawget(_G, 'json') or { }

crappy hack, I know :/

It will do for now, thanks heaps [richardhundt]! I can now get on with my life / things.

A note to others: make sure you've installed Tir like this - #4 (comment) not like this - http://tir.mongrel2.org/downloads/tir-0.9.3-3.rockspec