lua-users home
lua-l archive

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



On 2015-08-01 12:48, Dibyendu Majumdar wrote:

> Hi
> 
> One of the problems I have is how to improve the performance of  small
> Lua functions that don't do much but are there for convenience. The
> overhead of a Lua function call is quite high - so what I need is a
> way to inline the functions. Not being a compiler guru this is
> somewhat beyond my capabilities right now. So as a cheaper alternative
> I am thinking of introducing is support for macros as in C - allow
> user to define macros which are preprocessed textually before the
> parser runs. So I am looking for a small and fast opensource
> implementation of a macro preprocessor - the main capability I need is
> the equivalent of #define in C.
> 
> The license needs to be liberal so that it is compatible with MIT
> license. It should be written in C so that I can integrate it in Ravi.
> 
> If anyone here knows of an implementation that I should look at please
> let me know.

If you want it simple, why not just use 'cpp' as is. the only change
required there would be to allow '#' at the start of the line, which
afaik will not conflict with existing lua syntax, except for multiline
strings and comments. But since legacy code won't use preprocessor
directives, again you can just make this switchable by a commandline
switch or a #pragma and default it to off.

Sidenote: I am already using 'cpp' for some offline processing
(generate different source flavors from one input file) by:

  sed -e 's/--#/#/g' | cpp -w -

with this I can use
 --#define foo bar
like pp directives
 

Otherwise, in the long run I would prefer a much saner
macro/metaprogramming solution, Think about metalua, maybe a 'little'
less features but some way to hook into the parse tree and manipulate
it at compile-time with lua code itself would be close to awesome.
possibly ravi's type system and some optimizers could be implemented
in this way already.


	Christian



> 
> Thanks and Regards
> Dibyendu
>