[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: non random thoughts of a Lua n00b
- From: skaller <skaller@...>
- Date: 29 Dec 2004 23:08:32 +1100
On Wed, 2004-12-29 at 21:51, Frank Bechmann wrote:
> seems to be a new approach or is this anyhow
> related to srlua or bin2c mentioned by duck?
Not deliberately related (since I know nothing of them).
> What do you mean w/ "high level code"?
Um .. the script you can use to manipulate
the wrapped C lua API is a full on statically typed
high level language. Comparable to ML I guess:
much higher level than C++.
> Will Lua script compiled to C?
The second part of the project would be
a Lua script to C++ translator. In principle,
this is just 'luac', except it would produce
text containing C API calls instead of bytecodes.
> Wouldn't it be the easiest way to "just"
> somehow pack (e.g.) zip the various Lua sources and magically
> add them to the executable which will then "find" them when started?
That may be the case, you'd have to ask experts in both
Lua and various OS about that. However that is trivial
to do in C right now -- see 'Programming in Lua' book.
The following Felix program is a Lua interpreter,
the Lua code is embedded as a compiled
string... the example is the same as the one in the
'Programming in Lua' book:
s := str (lua_tostring(L, -1));
writeln (stderr, s);
lua_pop(L, 1); /* pop error message from the stack */
L := lua_open(); /* opens Lua */
C_hack::ignore(luaopen_base(L)); /* opens the basic library */
C_hack::ignore(luaopen_table(L)); /* opens the table library */
C_hack::ignore(luaopen_io(L)); /* opens the I/O library */
C_hack::ignore(luaopen_string(L));/* opens the string lib. */
C_hack::ignore(luaopen_math(L)); /* opens the math lib. */
lines := 'print "Hello"', 'print (1)';
///********************************** LUA PROGRAM HERE
var i = 0;
until i == 2 do
l := C_hack::enconst[char] (cstr s);
n := C_hack::size_of (len s);
line := C_hack::enconst[char] c"line";
var error = luaL_loadbuffer(L, l, n, line);
if error != 0 do
error = lua_pcall(L, 0, 0, 0);
if error != 0 do
> I'm by no means a system programmer, but IIRC that was the idea for Python.
That was *one* idea for Python. Several others were tried.
There is a Python to C compiler (py2c?), which does exactly what
I described above -- it parses Python like the interpreter but
generates C API calls instead of bytecode.
Another approach was my own project, Vyper, which began as a
Python iterpreter written in Ocaml, with the idea of
executing initialisation code, and then dumping the resulting
module dictionaries in C form.
However the code I'm working on isn't designed to
help pack Lua into an executable. That isn't the purpose,
it's just a side-effect that may be useful to you.
John Skaller, mailto:firstname.lastname@example.org
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net