From 8d8f509bb2036757b687c1752c78d45ad63f6edd Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Wed, 19 Feb 2014 00:16:13 -0800 Subject: [PATCH] custom compiler docs --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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