[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lua_load hook (was On the subject of Lua's grammar... --[[ ]])
- From: Andre de Leiradella <leiradella@...>
- Date: Fri, 28 Nov 2003 10:43:48 -0200
Hi All,
luareader (http://www.geocities.com/andre_leiradella/#luareader) uses the
lua_load hook to load chunks of data from a stream and pre-process the lua
source code to change statements on the "@id", "@id(...)" and "@@id(...)"
forms into something else, making it easier (at least for me) to write OOP
code with lua (with the help of some metatables also):
Button = class(Control)
function Button:new(x, y, width, height, caption)
@@new(x, y, width, height) -- translates to inherited(self, "new", x, y,
width, height)
@caption = caption -- translates to self.caption = caption
end
If someone is willing to write a C-like preprocessor for Lua maybe luareader
can be helpfull.
By the way I have a newer version of lua_reader which is able to read source
and pre-compiled lua files from files or memory. The bytes, be in a file or
memory, can be gzipped or bzipped and can be grouped into a tar file that
can be automatically iterated to execute Lua code. It comes with a different
version of bin2c:
usage: bin2c [-help] [-?] [-quiet] [-input input_file] [-output output_file]
[-name lua_file_name] [-function function_name]
[-trace trace_function_name] [-error error_function_name]
[-compressed]* [-bunzip2]* [-gunzip]* [-tar iterator_function]*
[-classpp field_format method_format inherited_method_format]*
which automatically generates C code that calls luareader to execute Lua
code from memory in tar, tar.bz2, tar.gz, or plain code, pre-compiled or
not, with the option of pre-processing it with the OOP module.
If anyone is interested in luareader please let me know, I can release it
with the same license Lua has in one or two weeks.
Regards,
Andre de Leiradella
http://www.geocities.com/andre_leiradella/
--------------- Mensagem Original ---------------
Message: 15
Date: Thu, 27 Nov 2003 15:12:03 -0200
From: Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
Subject: Re: Re[2]: On the subject of Lua's grammar... --[[ ]]
To: lua@bazar2.conectiva.com.br
Message-ID: <200311271712.PAA04195@lua.tecgraf.puc-rio.br>
>RH> How about Lua sending the text through some preprocessor first?
>
>I think some sort of hook function might be neat, that is called
>before the lua code is actually compiled, and may alter the source
>code. With such a thing, C style #defines could be implemented, but
>also more complex things like a scheme-style hygienic macro
>preprocessor. I have no need for that currently, but it would be cool
>to have. Might pose some interesting problems, though...
A primitive form of hook already exists because lua_load, which is the
*only*
way to compile Lua code, calls a user function to get blocks of data. In
this
function, you can do as you please. I'm not saying that it's easy, I'm only
saying that the mechanism is already in place.
--lhf