mirror of
https://github.com/TangentFoxy/etlua.git
synced 2025-07-27 18:42:17 +00:00
custom compiler docs
This commit is contained in:
30
README.md
30
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 <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
|
||||
|
Reference in New Issue
Block a user