views:

292

answers:

5

Hi all,

I am developing, in C++, a Computer Aided Design package for Printed Circuit Boards and Schematics (aka EDA CAD). It uses Lua for some specific things, but I would like to expand the role of Lua so that it implements much of the user interface logic.

I would like to re-build the internals in a way which lets people change the behaviour of the user interface easily by editing the Lua, and also add brand new functionality.

The problem is, short of exposing some kind of massive API to the Lua code, I can't think of a good way to do this. I suspect that a massive API, with a function call for everything I can think of is probably a bad design. How can I design a system which lets users implement things I hadn't even thought of?

Is there a good document or book I can read, or a forum where people talk about this kind of thing. I have been searching and thinking for many months now, and I'm still not sure what the answer is.

BTW, the project is called LiquidPCB.

Many thanks

Hugo

A: 

Try SWIG (Simplified Wrapper and Interface Generator). It can generate Lua wrappers for existing C/C++ header files. It will allow you to quickly expose all the APIs to Lua. Based on your experience then you can decide on different architecture.

Nitin Bhide
My question is much less about Lua, and much more about the *structure of the application*. I could be using Lua, or Python, or C++. The question really is: "What should the interface between the application and the plugins look like?"
Rocketmagnet
+1  A: 

It is clear that you will need to expose some functions to lua through your API so that developers can compose and combine those features.

I stumble accross this good presentation on how to properly design an API and the included recommendations match what I have done in the past. It will help you guide your design.

Once you have an API, I recommend using the command pattern in lua or in C++ to create a bridge with the UI. In the past, I have encapsulated each API call in a Command and the command could then be called via script. I don't know lua but I know that Python is a good script language to use with your commands.

Good luck with your project.

David Segonds
A: 

Opensource the project?

By the sounds of it your users are going to have a certain level of programming knowledge, and they are also going to want to implement new features. In this way the fulfil two roles, as the client and the developer.

Why not have a public readonly source tree that they can check out, work on and submit patches to you. If you then deem their work to be good enough and relevant enough you can include it in the next release.

If you deem the developer good enough in general you could give them direct write access to the source tree and start planning new features with them.

Greg B
It's been on Sourceforge for ages. It's called Liquidpcb.
Rocketmagnet
+1  A: 

I'd like to point out what's happening in the development of the new Blender version, 2.50. The previous Python API used to be a hand written layer trying to wrap most functionalities. The new API will automatically wrap access to data structure through a Data API. More documents here.

UncleZeiv
A: 

The new Sketchup Ruby API is a pretty good example of what you are looking for. Compare it with the older API for some interesting insights on what not to do.

Vulcan Eager