[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaMacro
- From: "steve donovan" <steve.j.donovan@...>
- Date: Fri, 4 Jan 2008 08:28:41 +0200
On Jan 3, 2008 6:06 PM, Eike Decker <eike@cube3d.de> wrote:
> #define printint(x) printf("%s = %i\n",#x,x)
That's a nice example, because it makes adding debug variable writes easier.
In LuaMacro:
macro.define('P",{"arg"},@ print(_STR(arg)..' = '..arg) @)
so
P(alpha)
prints 'alpha = 2'
Very easy to make that go to a logger, etc. And make a simple change
to the macro, and the debug writes don't appear in the 'release'
build.
Other examples abound. For instance, in LuaJava, objects get created like this:
obj = luajava.newInstance("java.lang.Object")
It is not difficult to make a macro 'new' and write this:
obj = new Object
which would be smart enough to know that a unqualifed class name comes
from the 'java.lang' package.
BTW, I am no longer happy with @ .. @ token list literals, so I've put
in a little lexer, so one can use simple quoted strings instead. This
has other useful consequences, apart from reducing the lexical noise
;)
I would hesitate to use macros in code which I'm sharing with the
community. But debug and build support, particularly test frameworks,
can be made more painless.
steve d.