lua-users home
lua-l archive

Re: Noob's attempt at Lua

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great siiky once stated:
> Hi there, list o/
 Hello.
> But there's the problem (for me at least): can a table be callable? 
> Would that be possible to do?
 Yes, it's easy to do with the __call metamethod. An example:
	mt = { __call = function(self,x) return x end }
	t = {}
	setmetatable(t,mt)
	print(t(3))
> 2. The server's replies are almost all in JSON. Is it worth it to make 
> the parser parameterized such that a user of the library may use any one 
> they like? For whatever reason -- it could be performance, less deps, 
> &c. It should be really easy to implement, it's just one extra instance 
> parameter.
 This might be quite involved, as I counted 45 JSON modules in LuaRocks
alone. Just looking at three of them:
dkjson defines the following:
	json.decode(string,position,nullvalue,mt)
		string - data to decode
		position - starting position, 1 if not given
		nullvalue - value to use for JSON null , nil if not given
		mt - returned data has metatable if not nil
org.conman.parsers.json (and org.conman.parsers.jsons) defines:
	json:match(string,position)
		string - data to decode
		position - starting position, 1 if not given
and to set a custom null value, a global variable 'null' can be defined.
json-lua defines:
		JSON:decode(string)
with no way to specify a value for JSON's null.
> 3. If you'd like to spend some of your precious time to educate a 
> noob, could you take a quick look at the code and see if there are any 
> glaring points to improve? :)
 Only one thing came to mind: string.format("%q",s) will return some
characters escaped (see the manual for more information).
 -spc

AltStyle によって変換されたページ (->オリジナル) /