lua-users home
lua-l archive

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


Hi,
sorry if I caused a stir on this lua to javascript.
Did not mean to.

Yes, I pretty much wanted to get to as simple subset as
possible of lua to convert to javascript.


Really what I needed was to allow users to write simple
'if-statements' that would enable/or disable Javascript 
gui controls, based on some conditions.


So the resulting javascript was to be executed with eval
within a webpage (which is by isteself a security risk)


So what I did is allow users to enter 
those logic statements in lua, have metalua validate
the syntax, parse it out, give me an AST tree
Then I converted them into java syntax, and

using my ContextSensitive call back functions, I would validate
if the user was trying to call my 'secure and vetted' javascript
functions -- and if not -- just error out or replace them with
a 'default function.

So it is really a domain-specific language with 'lua syntax' as a base.

I liked my approach (besides for being mine :-) ) because I figured
in the future I would add more and more functionality as need arises.
And lua syntax and metalua's parsing and AST handling, I felt, where
very good basic foundtations (so I would not need to rewrite things
from scratch every time I needed to add another construct).



In the mean time I saw two requests for my little script
a) support lua tables
b) fix the problem where if a function call occured outside of ifblock
   it would not get translated (it was not a user error)

so I fixed both
  I now support lua tables by jusing json encode (so it now relies
on luarocks and json)

The new code is here

http://pastebin.com/d13a227c6


Example:

-- lua code ----

call_func({xyz="a",m="b"})

if my_js_tb({1,2,3}) < AB  then
  call_func2(aa)
else
  call_func3(bb)
end
-----------------------



--- gets translated into  javascript  ---
 call_func({"m":"b","xyz":"a"}) ;
if( js_iop_lt( my_js_tb([1,2,3]) ,AB)
)
{
 call_func2(aa) ;
}
else

{
 call_func3(bb) ;
}/*end of if*/
------------------------------------



Regards,
Vlad









On Thu, 13 Nov 2008 15:28:15 -0500, "Javier Guerra" <javier@guerrag.com>
said:
> On Thu, Nov 13, 2008 at 3:21 PM, Fabien <fleutot+lua@gmail.com> wrote:
> > It's not difficult to add support for and/or operators in the translator,
> > but as I understood, Vlad only needs to support a limited subset of Lua, and
> > quite sensibly didn't focus on things he didn't need.
> 
> arguably, it's not too hard to find a limited subset of Lua that
> coincides with JavaScript after a few text replacements (begin/end =>
> {  }  and such)
> 
> > Actually, if you plan to write a translator that converges toward full Lua
> > support, some architectural choices made by Vlad would be seriously
> > unoptimal, although they made sense in his case.
> 
> that would be a really amazing project, i guess it would amount to a
> full compiler.
> 
> -- 
> Javier
-- 
  V S P
  toreason@fastmail.fm

-- 
http://www.fastmail.fm - And now for something completely different┘