https://github.com/rvirding/luerl
It is not a full Lua but it implements most of the language and a sizeable portion of the standard libraries. The user interface is lacking but I am working on that. I am also working on improving the speed and extending the libraries.
Robert
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Robert
This is major cool-ness. I am not going to sleep this weekend. :)
Sure will! Matthew has already mentioned the most important one -
calling Erlang modules/functions. My laundry list for the standard
libraries would definitely be io + file, followed closely by
coroutines, modules and packages. It looks a lot like the stdlib
implementations just need to take their proper inputs (and the
stack/state), call the relevant Erlang stdlib implementation and
return this in the correct format along with St.
Is this the right general pattern? Allowing (obviously) for the
implementation to try and remain faithful to the documented semantics
of Lua's standard library - because if so, it looks like assisting
with implementing additional standard library functions should be
relatively easy.
Some of this is more difficult. The current interpreter is not really suitable to do coroutines on. The others should be doable, some are just work like implementing there own (non) regular expression patterns. What is also needed is a good interface between erlang and Lua.
> Is this the right general pattern? Allowing (obviously) for the
> implementation to try and remain faithful to the documented semantics
> of Lua's standard library - because if so, it looks like assisting
> with implementing additional standard library functions should be
> relatively easy.
At the moment I am still working with the internal data structures and many of the libraries need this information. Fro examples I have tables as orddicts; while this is not a bad choice if it were to change them many internal functions would have to change. I am now looking at alternatives for storing the tables; I am testing orddicts, arrays, the process dictionary and ETS. Arrays and the process dictionaries seem the best so far.
I have given some more comments in http://news.ycombinator.com/item?id=3610332 .
Suggestions are welcome.
Robert
I am so glad to hear that. I just read about female gladiators and PHP in Erlang somehow sounds equally chilling.Doing PHP in Erlang would not be impossible ...
I have given some more comments in http://news.ycombinator.com/item?id=3610332 . Suggestions are welcome.
On 2/20/12 3:38 AM, Robert Virding wrote:>> Re ycombinator:I have given some more comments in http://news.ycombinator.com/item?id=3610332 . Suggestions are welcome.
>> "Lua is a nice, small, relatively clean language."
I experience Lua as very magic, in the non-least surprising sense.
It can be so overloaded that it can be hard to guess what a simple bit of Lua code really does. Which is maybe not ideal for an DSL
Since __metatable is on the TODO list, maybe Luerl hasn't yet run into those waters.
I'd expect challenges there because the magic stems from Lua's formidable small- & cleanness -- or maybe Erlang turns out a marvelous fit. Certainly a very exciting side of the experiment.
>> "However, the interface between Erlang and Lua in luerl is definitely faster so for smaller amounts of work it may be better."
This is a very exciting point - and all it needs for an answer to the 'practical use' question. I'm anxious to see how you will eventually implement the tables.
To go for speed, wouldn't you have to make a choice based on table size? Isn't there an absolute threshold where lists and trees just become to expensive to 'udate'? I measured structures once and the cost of flat vs deep structures' mutations was as expected [1].
Is it known lore from when on ets are more performant than, say, trees?
The table structure in Lua has been endlessly debated on the Lua list. Good thing you are probably striving for a true image rather than a 'better' Lua. The temptations would be endless.
However, if you were to restrict yourself to a version that e.g. leaves metatables out, it would not really be Lua, but as a DSL still very useful. Maybe -- even more so.
Henning
[1] http://www.eonblast.com/blog/cost-of-mutation/
----- Original Message -----On 19 February 2012 00:32, Robert Virding <robert....@erlang-solutions.com> wrote:Report bugs and missing features.
What is also needed is a good interface between erlang and Lua.
luaL_dofile
[-0, +?, m]
int luaL_dofile (lua_State *L, const char *filename);
Loads and runs the given file. It is defined as the following macro:
(luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))
It returns false if there are no errors or true in case of errors.
luaL_dostring
[-0, +?, –]
int luaL_dostring (lua_State *L, const char *str);
Loads and runs the given string. It is defined as the following macro:
(luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))
It returns false if there are no errors or true in case of errors.
luaL_loadstring
[-0, +1, –]
int luaL_loadstring (lua_State *L, const char *s);
Loads a string as a Lua chunk. This function uses lua_load to load the chunk in the zero-terminated string s.
This function returns the same results as lua_load.
Also as lua_load, this function only loads the chunk; it does not run it.
luaL_newstate
[-0, +0, –]
lua_State *luaL_newstate (void);
Creates a new Lua state. It calls lua_newstate with an allocator based on the standard C realloc function and then sets a panic function (see §4.6) that prints an error message to the standard error output in case of fatal errors.
Returns the new state, or NULL if there is a memory allocation error.
[snip] I had planned something along the lines of:
| |
Eonblast Corporation hdie...@eonblast.com +1.404.418.5002 w www.eonblast.com |
I haven't posted to the mailing for a very long time, but this post got my imagination going. Can someone describe to me the capabilities of a Lua interpreter (i.e. this one) and what it can be used for? I haven't had the time to look into Lua yet, so I am a complete ignoramus on this subject :)
Thanks,
Rudolph
1. I want to experiment with implementing an imperative language with mutable global state on top of Erlang. A goal was to do it in straight Erlang without extensions.
2. I am giving a talk on implementing DSL's on Erlang at the next Erlang Factory in San Francisco in March, http://www.erlang-factory.com/conference/SFBay2012 (be there, it's going to be good, the whole factory I mean), and I wanted to be able to give practical experience from implementing a real-life imperative mutable data language. Lua is a nice, small, relatively clean language and is a good choice for this. And it is actually in use. I was also considering PHP or Javascript but they are definitely not small and clean.
3. Lua is an interseting language in its own right and has some cool ideas. You can get quite far with a few simple primitives. I don't know if these would be transferable to Erlang.
4. I like implementing languages.
Because Lua has mutable data and we are implementing it on top of Erlang it will never be as fast as a "real" Lua implementation. Some valid reasons you may want to use it:
- You only have to run a little Lua code but don't want the hassle of including a Lua system.
- The Lua code are running is only in small short Lua chunks so the the extra execution time may be offset by the faster data transfer.
- You have many cores and this would allow you to run Lua in parallel.
- ...
Luerl is a subset of Lua but most of the language now works. I am working on the standard libraries but they are still lacking. Some will never been done as they are very implementation specific, for example debug.
Robert
Hi Henning,
Ok we will go towards making them more Lua-C like. But we are running in an Erlang environment so they will handle errors in an Erlangy way:
- The 'eval' functions will catch errors and return {ok,Result} | {error,Reason}.
- The 'do' and 'call' functions will not catch errors and return {Result,NewState}. Errors caught in the Lua code, with 'pcall' which does not exist yet, will of course not generate an error at the Erlang interface.
- We will initialise/cleanup the state with 'start'/'stop' in an Erlangy way.
- We will 'encode'/'decode' Lua data.
- And we will both 'load' and 'compile' Lua and load/compile(String) -> {ok,Form} | {error,Reason}.