lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Fri, Feb 25, 2011 at 10:42 PM, Robert G. Jakabosky
<> wrote:
> It might be possible to do something like:
>  c_call "int" "function_name" { P"int x", P"int y" }

I'm a little wary of using tricks with Lua syntax to accomplish DSL's
in the manner seen in LPeg (without re) [1] and Coat [2].
Syntactically it sort-of resembles in a declarative way what we're
trying to represent, but uglier.  Semantically, it's a whole different
bag of crazy tricks underneath, and the user might not be isolated
from this.  At least with LPeg, the stated justification [1] is for
patterns to be manipulatable as first class objects in Lua, and the
semantics are not that far off.

Alternate options include keeping the syntax pure data (e.g.
XML/s-expressions/JSON or plain Lua tables, like in LuaRocks
rockspecs), implementing a nice parser (like Mike did for FFI and
Roberto did for LPeg re), or using a more imperative OO builder-like
approach (as in Scons and others [3-4]).  The imperative style may be
worth considering:

  local m = module "gd"
  m.constructor {name='newTrueColor', callstyle='ccall', ret='gdImage
*', symbol='gdImageCreate', parameters={ "int", "sx", "int", "sy" }}
  m.constructor[[newTrueColor ccall gdImage * gdImageCreate(int sx,
int sy)]] -- possibly with shorthand too
  if condition then -- the imperative style permits control structures
    m.destructor {.....}

[4] -- e.g.
env.Program{'hello', 'hello.c', LIBS={'gl', 'glut'}}