Skip to content

Commit

Permalink
custom compiler docs
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Feb 19, 2014
1 parent a0aad3e commit 8d8f509
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Expand Up @@ -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 <https://github.com/leafo/etlua/blob/master/etlua.moon#L42> 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
Expand Down

0 comments on commit 8d8f509

Please sign in to comment.