lua-users home
lua-l archive

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


> Here's what I'm currently trying to do in a recent
> project of mine.  I'd like to use CBuilder just as a
> design tool for my application (forms etc.) but
> implement all application logic in Lua.  No fancy
> binding of everything from C++ (Pascal) to Lua, but
> just enough to wire the UI to Lua (both ways) with as
> little effort as possible.
(...)
> As an aside: I prefer handcoding Lua bindings for
> *specific* API's (and classes) above using automated
> tools like tolua etc. so I'm definitely not aiming for
> anything that fancy...

Sounds really great. That is what i would do if i needed to.
But i think the discussion here is to have a quick way to porting
existing classes to Lua without writing a whole new wrapper code.
For small and specific usage (some standard classes and some standard
functions) it is easy. But if you have an entire program using
classes and have to change them a lot of times then you are more
likely to thinking about an automated solution. Don't you agree?

> In my small project I come a long way by just binding
> very standard properties and events (Caption, Name,
> Text, OnClick, etc.)  All this is done without a code
> generating tool (other than CBuilder that is), just a
> handful of simplistic VCL/Lua helper functions.

Sure. Exactly. For that I said we could use the already-there RTTI.
In RTTI you can specify an object, a property name and the value
as a string and the RTTI do the rest. So, this code would be
relatively simple to implement:

local btn = VCL.TButton{ -- LTN7 compatible
  name='Button1',
  caption='Click me, quickly!',
  left=5,
  top=5,
  width=100,
  height=20
}

-- and to define some properties after this:

btn:set{
  caption='Good boy ;)',
  enabled=false
}
-- Note i used the word 'set' as it is a keyword in Pascal.
-- So, there will be no properties with this name :)

-- Or you could implement this - although I think it is more
-- time-consuming:

btn.caption = 'Good boy ;)'
btn.enabled = false


This way, you only have a few functions to read/write
these values from/to VCL.

But here are some things we should have to work-around:

- Event handlers:  btn.onclick = function() print('hello from lua') end
- Component reference: btn.Parent = frm -- frm is a variable created the same way 'btn' was - Functions/procedures: Register them manually. Only the most important, of course.


> For those interested, I can continue this discussion
> off-list if I make some progress worth mentioning at
> all.

Yes. I wonder how many people in this list is actually wishing for the end of this delphi/cppbuilder discussion. LOL ;)


Romulo