guile-devel
[Top][All Lists]
Advanced

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

Re: someone please implement a lua language


From: Andy Wingo
Subject: Re: someone please implement a lua language
Date: Mon, 12 Jan 2009 20:30:53 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Hi Derek,

I'll copy the list, as a couple other people had similar questions. I
hope you don't mind.

On Mon 12 Jan 2009 01:26, Derek Peschel <address@hidden> writes:

> So you're saying Tcl has Algol-like syntax?  That's a bit of a
> stretch. :)

Ooh, you're right. I don't know what I was thinking :)

>> That's cool! It would be interesting to enhance Lua with the rich
>> runtime of Guile -- all of POSIX, pthreads, and all of Guile's excellent
>> libraries.
>
> This is interesting, but I suggest you explain your point a little more.
> Are you planning to expose the Guile runtime as Lua functions or
> keywords?

Yeah, somehow. I haven't really thought it through. Lua code would exist
in its own module, and have an appropriate environment. Tables that are
used as functional environments would probably be mapped to Guile
modules. But the point of the exercise, besides showing that Guile can
host multiple languages, would be to add a couple primitives to lua that
would give lua code access e.g. to guile-cairo, or other guile
extensions.

> Are the runtimes compatible enough that you can do that kind of syntactic
> translation?

Well, to put it one way: if you can do Python on the JVM, you can do
anything. Less facetiously, I do think they're similar enough. We can
add opcodes to our VM if they are really needed.

> You could even use one of the Scheme parser generators to write the
> parser.

Yes!

> Do you think something like this will run?  (It's the only program I have
> on my system that uses Lua, AFAIK.)
> http://fillets.sourceforge.net/

That's a slightly different question, because there we'd have to emulate
the Lua C API as well -- definitely possible, but a bit more work. You'd
have to make a libguile-lua.

Just to have a look, I downloaded the source to fillets to see how big
Lua's C API was in practice:

    $ grep -rE 'luaL?_.*\(' . | grep -v lua_State | perl -p -e 
's/^.*(lua[^(]*)\(.*$/$1/' | sort -u

    lua_close lua_getinfo lua_getstack lua_gettable lua_gettop
    lua_insert lua_isboolean lua_isnil lua_isnumber lua_isstring
    luaL_checkint luaL_checklstring luaL_checknumber luaL_checkstring
    luaL_checktype luaL_error luaL_loadbuffer luaL_loadfile luaL_optint
    luaL_optstring luaL_ref luaL_unref lua_newtable lua_open lua_pcall
    lua_pop lua_pushboolean lua_pushcfunction lua_pushfstring
    lua_pushlightuserdata lua_pushliteral lua_pushlstring lua_pushnil
    lua_pushnumber lua_pushstring lua_rawget lua_rawgeti lua_rawset
    lua_register lua_remove lua_settable lua_toboolean lua_tostring
    lua_touserdata lua_type

It's actually not that bad. For Emacs Lisp, for example, we'd have to
implement a *lot* of C API.

> How would you compare Python or Ruby to Lua, as easy or useful langauges
> to integrate with the Guile runtime?

They are much bigger languages, with much bigger libraries. For Python I
would look more at using e.g. PyPy to compile to Guile-VM bytecodes. Lua
is small enough that I would do the parsing in Scheme.

Cheers,

Andy
-- 
http://wingolog.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]