Skip to content

Instantly share code, notes, and snippets.

Created July 22, 2014 09:43
What would you like to do?
Simple Macro example, allows you to have a string which shows when last compiled. Remember that your main has to be in a different project to the macro (for the moment)
package com.felstar.macros.timestamp
import scala.reflect.macros.blackbox.Context
import scala.language.experimental.macros
object TimestampMacro {
def timestampString: String = macro timestampMacro
def timestampMacro(c: Context): c.Tree = {
import c.universe._
val now = new java.util.Date().toString
object TimestampMain extends App {
val timestamp=com.felstar.macros.timestamp.TimestampMacro.timestampString
println(s"This was compiled at ${timestamp}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment