lua-users home
lua-l archive

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

therandthem wrote:
I would like to implement JavaScript over Lua.  This
will be the full ECMA-262 specification with the
ECMA-357 E4X XML entension.  Rather than create a
traditional interpreter I will to use Lua to create a
domain specific language (DSL) if that is possible.

One method is Logix found at Is the Logix approach, which runs on Python, necessary
in Lua?  Does Lua's meta-mechanisms make this easier
than the Logix approach?

I am posting this because I do not have enough
experience to do this very quickly on my own.  If
others would like to work on this, please let me know.

Here is my reasoning and motivation:
  -The Lua language engine is very fast and it will
get faster.  A co-worker recently commented, "Ruby is
slow because it is interpreted."  I replied, "No, it
is slow because it has a slow interpreter."
  -Because Lua is fast it is a good candidate to use
as a base for other (existing even) languages.  Lua is
not Object Orientated so there is no awkward object
model to object model translation.
  -JavaScript will always be with us.  The Rhino and
Spidermonkey engines are not fast.  When one needs to
use JavaScript one should have fast JavaScript.
  -Lua can do prototypes.

So, that's it.  My ultimate hope is that a clear way
to create DSLs in Lua will result from this effort. If it does then I will move on to implement a DSL for
PHP.  The ultimate goal is that any language with a
slow interpreter can be recreated as a DSL over Lua.

I am doing precisely this. My project is called Emma3D ( and you can download the code base right now. The Javascript piece is in its infancy though so I don't think it will be much use to you yet. Our team is small and so there is no telling how long before we have a full Javascript interpreter.

So far I have a set of Javascript compliant object (Object, Array and Math, still working on Date) as well as an object model that allows these sorts of objects to be written in C++ or Lua with a full set of Lua interface classes in C++. Currently this is all wrapped up in the Emma3D engine, which runs its own Lua interpreter. But I am just finishing up the work to split out the object oriented piece into a separate library called Fusion. Fusion gets delivered as a dll (on Win32), is built with 5.1-alpha and is compliant with the 5.1 packaging model.

With Fusion you can go:

    require "fusion"
    local a = Array()
    a[0] = 1
    a[1] = "hello"

and so on. I will be making this available as source and binaries for Win32 within the next few weeks. We will also be porting to Linux and MacOSX, but haven't had the time for that yet.

I am also writing a Javascript to Lua translator, based on a Bison grammar file, which will translate the JS source into Lua source, then that will be compiled. I don't plan on implementing the entire ECMAScript 3 spec. There are a few things that are problematic. For instance:

- the with statement
- exception processing
- regexp constants

I will also be using a modified Lua interpreter. Most Javascript constructs, other than the ones I mentioned above, have simple translations to Lua. But some, like continue, would be really hard to do. So I will use the existing continue patch, as well as another patch that I uploaded to handle issues with the comparison operators.

Finally, the Lua ':' semantics are problematic from a Javascript standpoint. I am looking into this right now. I may end up having to add a bit of syntax to Lua and marking "member" functions that need to implicitly push a self pointer. I haven't figured it out yet, but hopefully it will be tractable.

Anyway, my work is probably too early to be of use to you. I just wanted to let you know that this work is available and to give you a heads up about the pitfalls!

chris marrin                ,""$,          b`    $                             ,,.
                        mP     b'                            , 1$'
        ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'