lua-users home
lua-l archive

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


I briefly considered using JSON, but in the end it really didn't seem to be any 
improvement.

SAJAX is mostly an easy way to call server-side functions from client-side 
javaScript.  for this, JS puts the call parameters into an HTTP request, the 
server decodes them, calls the function, encodes the result and send it as the 
request response. the client JS decodes the result and acts accordingly.

so, there's two points where JSON could be used:
1) in the request: JS => Lua
2) in the response: Lua => JS

the main feature of JSON is that it's easy to decode in JS, and not hard to 
encode in most languages; therefore in JS => Lua it's no better than the POST 
parameters currently used to carry the function parameters.

in the response, Lua => JS, it could in theory make a difference; but since 
function result is usually a single value, it's not really better than just 
writint that value as the response content.  also, any performance gains from 
using the JS interpreter to decode JSON would make a difference only on the 
client and put some (low) burden in the server.  i think in most cases the 
client will have far more spare MHz to burn than the server.  and lastly, 
writitng a library that gets something from the net and blindly executes it 
(even if it's under JS) doesn't sound very safe... (isn't that what makes all MS 
products so hard to secure?)

so, for usual web apps with just a bit of AJAX (the main target of SAJAX) the 
answer is no, JSON doesn't help

BUT...

it's possible to create a full GUI in JavaScript, and the whole app running in 
Lua, kind of a Xwindows system, but over HTTP.  in this schema, it would make 
much more sense sending lots of data to the JS client, maybe encoding that in 
JSON would be useful.

------
Javier