[euwren](https://github.com/liquid600pgm/euwren) uses macros to create a DSL 
that allows its users to easily add scripting support to their programs.
    
    
    import euwren
    
    type
      Greeter = object
        target*: string
    proc newGreeter(target: string): Greeter = Greeter(target: target)
    proc greet(greeter: Greeter) = echo "Hello, " & greeter.target & "!"
    
    var wren = newWren()
    wren.foreign("greeter"):
      Greeter:
        [new] newGreeter
        greet
    wren.ready()
    
    
    Run

Then, scripts like this can be executed using `wren.run(sourceCode)`:
    
    
    import "greeter" for Greeter
    
    var greeter = Greeter.new("world")
    greeter.greet() // -> Hello, world!
    greeter.target = "Nim"
    greeter.greet() // -> Hello, Nim!
    
    
    Run

Because Wren is a C library, you'd normally have to deal with a low-level, 
verbose API full of passing pointers around and other unsafe things. euwren 
abstracts that away, and provides a much more user friendly API that doesn't 
require non-idiomatic code to be used.

euwren's `foreign()` is a prime example of how macros can lead to cleaner and 
more maintainable code: reading a list of names is much easier than reading 
through a bunch of `addProc` and `addClass` calls with low level procs mixed 
inbetween. This makes every proc you bind consistently the same, no matter what 
it is, which embraces the DRY rule.

Reply via email to