Lua in JavaScript

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua in JavaScript

Ketmar Dark-2
we have Lua in Lua. so why not write Lua in JS? it would be fine to
write DHTML in Lua... %-)

really, i think that Yeliang can be taken as a reference. i've seen
Lua->JS converter, but it is old and buggy. does somebody interested in
such a... (stupid? let's say "funny") project? %-)

cr
Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

cr
On Wed Jul 25, 2007 at 08:15:58PM +0300, Ketmar Dark wrote:
> we have Lua in Lua. so why not write Lua in JS? it would be fine to
> write DHTML in Lua... %-)

instead of JS? theyre practically the same language, only JS calls its objects 'objects' instead of tables.. look closer. the differences are mostly syntax.. and heavier/less-agile implementations (typically C++ interpreters and heavily intertwined with browser code) w/ less non-html standard-library support.

maybe you could make a write a pretty trivial lua<>JS rewriter if you prefer ones syntax over the other, i prefer Ruby's syntax to either..

> really, i think that Yeliang can be taken as a reference. i've seen
> Lua->JS converter, but it is old and buggy. does somebody interested in
> such a... (stupid? let's say "funny") project? %-)

what exactly is the project? id be more interested in implementing CSS and DOM layout/events in Lua using Cairo/Glitz, so i can stop giving away 400mb of RAM and most my CPU to firefox, than the other way around..

have you benchmarked LuaJIT vs Tamarin? 

Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Rob Kendrick
<> wrote:
> On Wed Jul 25, 2007 at 08:15:58PM +0300, Ketmar Dark wrote:
>> we have Lua in Lua. so why not write Lua in JS? it would be fine to
>> write DHTML in Lua... %-)
> 
> instead of JS? theyre practically the same language, only JS calls its objects 'objects' instead of tables.. look closer. the differences are mostly syntax.. and heavier/less-agile implementations (typically C++ interpreters and heavily intertwined with browser code) w/ less non-html standard-library support.

There are tricky aspects of cleverer more advanced aspects of each
language which are difficult to map onto the other, though.  Syntax is
the easy bit.

> maybe you could make a write a pretty trivial lua<>JS rewriter if you prefer ones syntax over the other, i prefer Ruby's syntax to either..

Somebody in #lua made an amusing comment about Ruby users.  I will not
repeat it here. :)

I'm interested in a good JavaScript -> Lua converter, if anybody happens
to know of one.  I'm involved in a web browser project designed for
low-powered resource-constrained machines, and Spidermonkey's a little
too heavyweight :-/

B.


Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Ketmar Dark-2
In reply to this post by cr
On Wed, 25 Jul 2007 13:37:30 -0400
"<>" <[hidden email]> wrote:

> instead of JS? theyre practically the same language, only JS calls
> its objects 'objects' instead of tables.. look closer. the
> differences are mostly syntax.. and heavier/less-agile
and i hate c-like syntax. %-) this is one of the reasons of my
Lua-migration: "Lua is not C". %-)

> maybe you could make a write a pretty trivial lua<>JS rewriter if you
> prefer ones syntax over the other, i prefer Ruby's syntax to either..
i thougth about Lua->JS and Lua->PHP converters. Lua->PHP is not
necessary anymore, 'cause i'm in process of writing my own CGI
framework (no, Kepler is not a choice of mine %-). i have PHPish tags
and $-substitutions, what more? %-) includes, debug console, error
reporting... it all works. %-)

> what exactly is the project? id be more interested in implementing
> CSS and DOM layout/events in Lua using Cairo/Glitz, so i can stop
> giving away 400mb of RAM and most my CPU to firefox, than the other
> way around..
i want Lua compiler and VM in JS. or at least `reworked' VM. something
like `protype' -- a framework, which will compile and run Lua code in
browser. i know that i'm crazy, but may be i'll try to write some code
anyway... programming isn't just a money-work -- i like to make
something just for fun... %-)
one wrote Forth in BASH, why don't write Lua in JS? %-)

> have you benchmarked LuaJIT vs Tamarin? 
no. actually, i'm pretty sure that i'll not switch away from Lua, so
just don't making any benchmarks. and i want Lua in browser, so i
interested only in spdermonkey (Tamarin will come later) and Opera js
engines (and no, i event don't plan to support micro$oft JS engine %-).

but i'm curious... may be i'll try T., tnx. %-)

Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Rob Kendrick
Ketmar Dark wrote:

> i thougth about Lua->JS and Lua->PHP converters. Lua->PHP is not
> necessary anymore, 'cause i'm in process of writing my own CGI
> framework (no, Kepler is not a choice of mine %-). i have PHPish tags
> and $-substitutions, what more? %-) includes, debug console, error
> reporting... it all works. %-)

Aha, another Lua-based web framework!  These seem to be as fashionable
as picture gallery generators :)  Also consider looking at Aranha for
inspiration: http://www.digital-scurf.org/software/aranha

B.


Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

David Given
In reply to this post by Rob Kendrick
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rob Kendrick wrote:
[...]
> There are tricky aspects of cleverer more advanced aspects of each
> language which are difficult to map onto the other, though.  Syntax is
> the easy bit.

This is actually something I've been thinking about --- do you have any
pointers on these issues that I can follow up on?

- --
âââ ïïïïïïïïïïïïïï âââ http://www.cowlark.com âââââââââââââââââââ
â
â "There does not now, nor will there ever, exist a programming language in
â which it is the least bit hard to write bad programs." --- Flon's Axiom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGp5F4f9E0noFvlzgRAiIpAKCqhouk9v3PZ6/cZhoSMEbhOW555ACgjMNZ
DS+2QvGnLDR19YtUo/RXl74=
=1I/Y
-----END PGP SIGNATURE-----



Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Rob Kendrick
David Given wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Rob Kendrick wrote:
> [...]
>> There are tricky aspects of cleverer more advanced aspects of each
>> language which are difficult to map onto the other, though.  Syntax is
>> the easy bit.
> 
> This is actually something I've been thinking about --- do you have any
> pointers on these issues that I can follow up on?

JavaScript's generators, iterators, exceptions and array comprehensions
all concern me, as they're sufficiently different to how Lua does them.
 I seem to recall scoping is subtly different, especially when you get
into the mess of the new "let" keyword.

B.


Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Ketmar Dark-2
In reply to this post by Rob Kendrick
On Wed, 25 Jul 2007 19:07:25 +0100
Rob Kendrick <[hidden email]> wrote:

> Aha, another Lua-based web framework!  These seem to be as fashionable
> as picture gallery generators :)  Also consider looking at Aranha for
actually i just want to write a simple forum engine. and i started it in
a plain Lua. then realized that i need templates. then substitutions.
then debugging tools... i never planned to write a framework, honestly!
i just hate PHP... %-)

> inspiration: http://www.digital-scurf.org/software/aranha
i've seen this site, but i'm too conservative... i don't want to
install bazaar... %-)

Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Tony Finch
In reply to this post by David Given
On Wed, 25 Jul 2007, David Given wrote:
> Rob Kendrick wrote:
> [...]
> > There are tricky aspects of cleverer more advanced aspects of each
> > language which are difficult to map onto the other, though.  Syntax is
> > the easy bit.
>
> This is actually something I've been thinking about --- do you have any
> pointers on these issues that I can follow up on?

JavaScript does not index tables in the way that Lua does: the key is
converted to a string before being used. This matters when using tables
or functions as table keys.

Tony.
-- 
f.a.n.finch  <[hidden email]>  http://dotat.at/
IRISH SEA: SOUTHERLY, BACKING NORTHEASTERLY FOR A TIME, 3 OR 4. SLIGHT OR
MODERATE. SHOWERS. MODERATE OR GOOD, OCCASIONALLY POOR.

Reply | Threaded
Open this post in threaded view
|

RES: Lua in JavaScript

Rafael - SosCpdTerra
Hello Ketmar:


	I like how this project sounds. Maybe not a JS Lua VM. Maybe a
Plugin? I have one http server too, and I use lua on it just like php in
apache. Use lua like js can be really powerfull, including database access
to client script? Sqlite, cache and css can put one entire web site on the
local machine with just one bytecode file and a sqlite database. Wooow...
that sounds nuts... and pretty fast!!!

If you guys like to join... I will start this project just today.

Regards

Rafael


-----Mensagem original-----
De: [hidden email]
[[hidden email]] Em nome de Tony Finch
Enviada em: quarta-feira, 25 de julho de 2007 16:14
Para: Lua list
Assunto: Re: Lua in JavaScript

On Wed, 25 Jul 2007, David Given wrote:
> Rob Kendrick wrote:
> [...]
> > There are tricky aspects of cleverer more advanced aspects of each
> > language which are difficult to map onto the other, though.  Syntax is
> > the easy bit.
>
> This is actually something I've been thinking about --- do you have any
> pointers on these issues that I can follow up on?

JavaScript does not index tables in the way that Lua does: the key is
converted to a string before being used. This matters when using tables
or functions as table keys.

Tony.
-- 
f.a.n.finch  <[hidden email]>  http://dotat.at/
IRISH SEA: SOUTHERLY, BACKING NORTHEASTERLY FOR A TIME, 3 OR 4. SLIGHT OR
MODERATE. SHOWERS. MODERATE OR GOOD, OCCASIONALLY POOR.


Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Ketmar Dark-2
On Wed, 25 Jul 2007 15:52:57 -0300
"Rafael - SosCpdTerra" <[hidden email]> wrote:

> 	I like how this project sounds. Maybe not a JS Lua VM. Maybe a
> Plugin? I have one http server too, and I use lua on it just like php
> in apache. Use lua like js can be really powerfull, including
> database access to client script? Sqlite, cache and css can put one
> entire web site on the local machine with just one bytecode file and
> a sqlite database. Wooow... that sounds nuts... and pretty fast!!!
> 
> If you guys like to join... I will start this project just today.
yes, this would be great. but... my lovely Opera doesn't allows to do
this easily. %-( the only thing i can dream of is a simple Lua
scripting in webpages...

but... they done Java plugin, so there IS a way to so at leas such
thing... just fool Opera so it will think we are using Java -- as a
last resort? you point me in a very interesting direction, yes... this
thing definetely worth further investigation! it is not so thight
integrated in DOM as JS, but at least this is Lua in browser... Lua is
fast, lightweight and suits this fine.

btw, i believe that i've seen such project somewhere... may be even in
this list. but the project was stalled... am i wrong?

Reply | Threaded
Open this post in threaded view
|

RES: Lua in JavaScript

Rafael - SosCpdTerra
Im sure your Opera can work with plugins... if macromedia can do flash
plugin and java can do plugin too, WE CAN DO PLUGIN!!! :)
A fact on this project must be: Lua in browser. Yes, I think java can be
used, but is not my way of lightweight. We must consider search for other
ways to do so. I will love if we use Lua as dynamic link library for windows
and linux. Our job must be simply grant to the browsers, access to lua
language, such javascript. I will search more information before say there
are other projects or not, or how can we do that.

Regards

Rafael



-----Mensagem original-----
De: [hidden email]
[[hidden email]] Em nome de Ketmar Dark
Enviada em: quarta-feira, 25 de julho de 2007 17:15
Para: [hidden email]
Assunto: Re: Lua in JavaScript

On Wed, 25 Jul 2007 15:52:57 -0300
"Rafael - SosCpdTerra" <[hidden email]> wrote:

> 	I like how this project sounds. Maybe not a JS Lua VM. Maybe a
> Plugin? I have one http server too, and I use lua on it just like php
> in apache. Use lua like js can be really powerfull, including
> database access to client script? Sqlite, cache and css can put one
> entire web site on the local machine with just one bytecode file and
> a sqlite database. Wooow... that sounds nuts... and pretty fast!!!
> 
> If you guys like to join... I will start this project just today.
yes, this would be great. but... my lovely Opera doesn't allows to do
this easily. %-( the only thing i can dream of is a simple Lua
scripting in webpages...

but... they done Java plugin, so there IS a way to so at leas such
thing... just fool Opera so it will think we are using Java -- as a
last resort? you point me in a very interesting direction, yes... this
thing definetely worth further investigation! it is not so thight
integrated in DOM as JS, but at least this is Lua in browser... Lua is
fast, lightweight and suits this fine.

btw, i believe that i've seen such project somewhere... may be even in
this list. but the project was stalled... am i wrong?


Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Romulo Bahiense
In reply to this post by Ketmar Dark-2
Yes, Yindo, but is no longer maintained. It was something like a Flash plugin with, IIRC, Lua 4.

--rb

Ketmar Dark wrote:
On Wed, 25 Jul 2007 15:52:57 -0300
"Rafael - SosCpdTerra" <[hidden email]> wrote:

	I like how this project sounds. Maybe not a JS Lua VM. Maybe a
Plugin? I have one http server too, and I use lua on it just like php
in apache. Use lua like js can be really powerfull, including
database access to client script? Sqlite, cache and css can put one
entire web site on the local machine with just one bytecode file and
a sqlite database. Wooow... that sounds nuts... and pretty fast!!!

If you guys like to join... I will start this project just today.
yes, this would be great. but... my lovely Opera doesn't allows to do
this easily. %-( the only thing i can dream of is a simple Lua
scripting in webpages...

but... they done Java plugin, so there IS a way to so at leas such
thing... just fool Opera so it will think we are using Java -- as a
last resort? you point me in a very interesting direction, yes... this
thing definetely worth further investigation! it is not so thight
integrated in DOM as JS, but at least this is Lua in browser... Lua is
fast, lightweight and suits this fine.

btw, i believe that i've seen such project somewhere... may be even in
this list. but the project was stalled... am i wrong?




Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Ketmar Dark-2
On Wed, 25 Jul 2007 17:56:20 -0300
Romulo Bahiense <[hidden email]> wrote:

> Yes, Yindo, but is no longer maintained. It was something like a
> Flash plugin with, IIRC, Lua 4.
and it was closed source, afair.

Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Ketmar Dark-2
In reply to this post by Rafael - SosCpdTerra
On Wed, 25 Jul 2007 16:42:37 -0300
"Rafael - SosCpdTerra" <[hidden email]> wrote:


> Im sure your Opera can work with plugins... if macromedia can do flash
> plugin and java can do plugin too, WE CAN DO PLUGIN!!! :)  
yes.

> A fact on this project must be: Lua in browser. Yes, I think java can
> be used, but is not my way of lightweight. We must consider search
> for other ways to do so. I will love if we use Lua as dynamic link
> library for windows and linux. Our job must be simply grant to the
> browsers, access to lua language, such javascript. I will search more
> information before say there are other projects or not, or how can we
> do that.
but... Java and Flash plugins has no access to DOM. there are just
"windows" with their own controls, etc... there's no way to control DOM
as JS do. %-(

and NS plugin API is very restricted, afair. i'll google to refresh
my memories. %-)

sure, we can patch FF to use either JS or Lua as scripting language,
but Opera is closed source software... and Explorer... argh, i don't
want to talk about Explorer, albeit i nearly sure that IE can use Lua
exactly in this way thru Windows Scripting Host... %-))

and i don't like FF too (it is too fat and too slow %-( ). and anyway,
embedding Lua with the same abilities JS have means separate branch of
developing and constant patching... but i'm not an expert in FF. if we
can do thi only in FF -- this will be fine. *something* is definetely
better than *nothing*. %-))

Reply | Threaded
Open this post in threaded view
|

RES: Lua in JavaScript

Rafael - SosCpdTerra
We must consider having many browsers support such the most used ones, like
FF(yes, fat and slow), explorer(unsafe and not standard, but fast), opera(my
download choice too) and Safari(no comments...), if not all them (I think
that is the easy way.). My point is: Think our point must not be what
browser support. Must be how technology is so deep in actual DOM and open
enough to use it and write the binding. Start working with explorer or
firefox or whatever browser we choose is expect the browser companies see
the potential and use it. Safari use Lua!!! I don't know how... yet. A first
step can be just research and plan what can be done. Brain storm. Later we
filter what cant be used. A project... goals, etc... but not a workflow...,
please... I have just my free time to work on that.

Think a good start is stop the noise on the list. 

I can be directly find at [hidden email], any time. 
We can host the project somewhere.

Here is the safari lua file contents:

-- Main entry point for PubSub template expansion


local format  = string.format
local gsub    = string.gsub
local find    = string.find
local strsub  = string.sub

local concat  = table.concat
local tinsert = table.insert

local compiledTemplates = {}


-- shortcut for localized strings; just use LOC.kSomeKey or LOC['kSomeKey']
LOC = {}
locmeta = {}
function locmeta.__index(table,key)
    local value = pubsub.getLocalizedString(key)
    assert(value, "No localized string")
    rawset(table,key,value) -- cache the value, for performance
    return value
end
setmetatable(LOC,locmeta)

-- escape a string for substitution in HTML text
local kHTMLMap = {['<'] = '&lt;', ['>'] = '&gt;', ['&'] = '&amp;', ['"'] =
'&quot;', ["'"] = '&apos;' }
function escape( str )
    if str then
        return string.gsub(str, '([<>&"\'])', function(chr)
                                                return kHTMLMap[chr]
                                              end)
    else
        return str
    end
end



local function out (s, i, f)
    s = strsub(s, i, f or -1)
    if s == "" then return s end
    -- we could use `%q' here, but this way we have better control
    s = gsub(s, "([\\\n\'])", "\\%1")
    return format(" emit('%s'); ", s)
end


function translate (s)
    s = gsub(s, "<%%(.-)%%>", "<?lua %1 ?>")

    local res = {}
    local start = 1   -- start of untranslated part in `s'

    while true do
        local ip, fp, target, exp, code = find(s, "<%?(%w*)[
\t]*(=?)(.-)%?>", start)
        if not ip then break end

        tinsert(res, out(s, start, ip-1))

        if target ~= "" and target ~= "lua" then
            -- not for Lua; pass whole instruction to the output
            tinsert(res, out(s, ip, fp))
        else
            if exp == "=" then   -- expression?
                tinsert(res, format(" emit(%s);", code))
            else  -- command
                tinsert(res, format(" %s ", code))
            end
        end

        start = fp + 1
    end

    tinsert(res, out(s, start))

    return concat(res)
end


-- Compile the contents string and store the resulting function in
compiledTemplates[name]
function compileTemplate (name, contents)
    local prog = "return function(emit, model)\n" .. translate(contents) ..
"\nend"
    local code,err = loadstring(prog);

    if code then
        local f = code();
        compiledTemplates[name] = f;
    else
        error(err);
    end
end


-- Run the named precompiled template, with the given model
function applyTemplate (name, model)
    local f = compiledTemplates[name]
    if not f then
        error("template " .. name .. " not compiled");
    end
    
    local resultStrings = {};
    local function collectOutput(str)
        if str then
            tinsert(resultStrings, tostring(str))
        end
    end

    f(collectOutput, model)             -- SHAZAM! Evaluate the compiled
template
        
    return concat(resultStrings)
end


-----Mensagem original-----
De: [hidden email]
[[hidden email]] Em nome de Ketmar Dark
Enviada em: quarta-feira, 25 de julho de 2007 18:02
Para: [hidden email]
Assunto: Re: Lua in JavaScript

On Wed, 25 Jul 2007 16:42:37 -0300
"Rafael - SosCpdTerra" <[hidden email]> wrote:


> Im sure your Opera can work with plugins... if macromedia can do flash
> plugin and java can do plugin too, WE CAN DO PLUGIN!!! :)  
yes.

> A fact on this project must be: Lua in browser. Yes, I think java can
> be used, but is not my way of lightweight. We must consider search
> for other ways to do so. I will love if we use Lua as dynamic link
> library for windows and linux. Our job must be simply grant to the
> browsers, access to lua language, such javascript. I will search more
> information before say there are other projects or not, or how can we
> do that.
but... Java and Flash plugins has no access to DOM. there are just
"windows" with their own controls, etc... there's no way to control DOM
as JS do. %-(

and NS plugin API is very restricted, afair. i'll google to refresh
my memories. %-)

sure, we can patch FF to use either JS or Lua as scripting language,
but Opera is closed source software... and Explorer... argh, i don't
want to talk about Explorer, albeit i nearly sure that IE can use Lua
exactly in this way thru Windows Scripting Host... %-))

and i don't like FF too (it is too fat and too slow %-( ). and anyway,
embedding Lua with the same abilities JS have means separate branch of
developing and constant patching... but i'm not an expert in FF. if we
can do thi only in FF -- this will be fine. *something* is definetely
better than *nothing*. %-))


Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Jonas Bengtsson
In reply to this post by Ketmar Dark-2
Ketmar Dark wrote:
but... Java and Flash plugins has no access to DOM. there are just
"windows" with their own controls, etc... there's no way to control DOM
as JS do. %-(

Doesn't Flash at least have some access to the DOM? I thought this was something that was improved upon the last couple of years (but since I don't do Flash I have no hands-on experience). There are things like the Flash / JavaScript Integration Kit [1] and Flex-Ajax Bridge [2].

Cheers,
 Jonas

[1] http://weblogs.macromedia.com/flashjavascript/
[2] http://labs.adobe.com/wiki/index.php/Flex_Framework:FABridge


Reply | Threaded
Open this post in threaded view
|

RES: Lua in JavaScript

Rafael - SosCpdTerra
Jonas

I just think that is not the point of our plans. We like lua to be as
javascript is to the DOM. Not just some ways, but part of. Anyway... some
ways will be the start, I think.

[]

Rafael

-----Mensagem original-----
De: [hidden email]
[[hidden email]] Em nome de Jonas Bengtsson
Enviada em: quarta-feira, 25 de julho de 2007 18:38
Para: Lua list
Assunto: Re: Lua in JavaScript

Ketmar Dark wrote:
> but... Java and Flash plugins has no access to DOM. there are just
> "windows" with their own controls, etc... there's no way to control DOM
> as JS do. %-(

Doesn't Flash at least have some access to the DOM? I thought this was 
something that was improved upon the last couple of years (but since I 
don't do Flash I have no hands-on experience). There are things like the 
Flash / JavaScript Integration Kit [1] and Flex-Ajax Bridge [2].

Cheers,
  Jonas

[1] http://weblogs.macromedia.com/flashjavascript/
[2] http://labs.adobe.com/wiki/index.php/Flex_Framework:FABridge



Reply | Threaded
Open this post in threaded view
|

Re: Lua in JavaScript

Philippe Lhoste
In reply to this post by Ketmar Dark-2
On 25/07/2007 22:14, Ketmar Dark wrote:
btw, i believe that i've seen such project somewhere... may be even in
this list. but the project was stalled... am i wrong?

Beside the closed source Yindo, there were already discussions in this list about integrating Lua in browsers. Leading nowhere, IIRC, but digging out this (these) thread(s) might show information or point out problems.

FYI, both Java and Flash can communicate with JavaScript. JavaScript has been designed precisely to communicate with Java (see JavaScript: How Did We Get Here? <http://www.oreillynet.com/pub/a/javascript/2001/04/06/js_history.html>) and I saw somebody use a little Flash file to be able to put data in the clipboard (from JS) in a portable way, without bothering with security issues... (in FF)

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --