diff --git a/README.md b/README.md index 3ab0d9f..46eb2d7 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,36 @@ parser:run(second_fn, nil, buffer, #buffer) print(table.concat(buffer)) -- print 'Hello World' ``` +## Custom compiler + +If you need to customize the Lua code that is generated by etlua to integrate +with your own output buffers then you can provide a custom compiler. + +You can extend `etlua.Compiler` and override it's methods to control the +output. See for the +implementation of the default compiler + +For an example we'll create a debug compiler that prints whenever a template is +executed. + +```moonscript +-- create a custom compiler +import Compiler from require "etlua" + +class DebugCompiler extends Compiler + header: => + @push 'print("Running template")\n' + super + +-- try it out +import Parser from require "etlua" + +print Parser!\compile_to_lua "hello", DebugCompiler +``` + +`compile_to_lua` takes an optional second argument of the compiler class to +use. + ## License MIT, Copyright (C) 2014 by Leaf Corcoran