Skip to content

Instantly share code, notes, and snippets.

@yloiseau
Last active January 22, 2017 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yloiseau/ca03668ef3d592a75f69 to your computer and use it in GitHub Desktop.
Save yloiseau/ca03668ef3d592a75f69 to your computer and use it in GitHub Desktop.
more on golo macros

This was working! It's no more the case

module StructMacro

import gololang.macros.CodeBuilder

function pokemon = |typeName, sound| -> toplevel(
  structure(): name(typeName: getValue())
  : members("name", "owner"),
  augmentType(typeName: getValue())
  : withFunction(publicFunction()
    : name("makeNoise")
    : param("this")
    : block(
      returns(sound)))
  : withAugmentation("fightable")
)
module StructTest

import StructMacro

augmentation fightable = {
  function fight = |this, other| {
    println("## " + this: name() + " fight against " + other: name())
    println("> " + this: makeNoise() + "!")
    println("> " + other: makeNoise() + "!")
  }
}

&pokemon("Pikachu", "pika")
&pokemon("Salameche", "salameche")

function main = |args| {

  let pika = Pikachu("Pika", "Sacha")
  let charla = Salameche("Charla", "Lise")

  pika: fight(charla)

}
golo compile macros.golo && golo golo --files test.golo
## Pika fight against Charla
> pika!
> salameche!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment