Hello!
On Wed, Dec 4, 2013 at 3:04 PM, milspec wrote:
> how about this?
> Implement a Lua preprocessor directive:
> lua_preprocess preprocessor_logic.lua
> What does it mean?
> Everytime before a Lua-script gets compiled, the script
> preprocessor_logic.lua is executed and the whole script's sourcecode that is
> to be executed is passed to that script for manipulation. When the
> preprocessor_logic.lua script is done, openresty compiles the preprocessed
> Lua script.
Oh, I like this idea :) But we can make this more powerful by
1. allowing the filter to emit LuaJIT/Lua bytecode directly,
2. allowing the filter to be written in other languages by supporting
custom shell commands, as in
lua_preprocess cmd="perl /path/to/translator.pl"
3. allowing custom file extension mapping, like
# "content_by_lua_file foo.tt" will run perl-tt2-filter.lua:
lua_preprocess /path/to/perl-tt2-filter.lua ext=tt;
> Maybe make a function preprocess(source) mandatory in the
> preprocessor_logic.lua script?
>
For pure Lua preprocessor, I think we can just accept return value
from the code chunk. I don't like a predefined named function here.
> What is it good for?
>
> I could write my own preprocessor-extensions without the need for a
> templating system that is maybe slower.
>
> I could write a Lua-logic that allows me <? ?> tags at native luajit speed
> as it is just a string replacement before compilation.
> Other features are: autoincludes or "register_shutdown" alike features etc.
> that could be easily implemented then.
Right, a custom macro extension for Lua will be trivial. A template
language will be trivial. Also, complete higher level languages
targeting Lua (like MoonScript) will also be trivial :)
>
> I think the preprocessor is not that difficult to implement but the benifits
> are very versatile and who does not want/use it won't be influenced by it.
>
Yes, I can see that it has two major benefits:
1. abstracting away the underlying Lua language completely and saving
the intermediate Lua driver layer, and
2. easier (Lua) code cache without custom Lua modules.
I'm cc'ing the openresty-en mailing list to expose this discussion to
the whole community :) See http://groups.google.com/group/openresty-en
Best regards,
-agentzh