lua-users home
lua-l archive

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

On Wed, Jan 20, 1999 at 11:36:38PM -0200, Jay Glascoe wrote:
> I've read the Ref. Manual and perused the goodies in the "test" 
> directory. So, I feel fairly comfortable with Lua's language/syntax,
> but I'm still left wondering what a good Lua/C extension looks like. 
> Is there any code out there implementing, say, trees or matrices in C
> as Lua "userdata" types? 

Hmm.. I wrote some code to the mailing list a while back which
explained exporting C data-types as user-data types which act like lua
structures. I have a bunch of code which does different types of
extensions in my stuff, but it's pretty nasty and probably more
confusing than it is helpful.

> Also, at one point I thought I knew what "extension language" meant: I
> use Python all the time and implement compute-intensive tasks as C
> extensions (dynamically loaded, it's real cool).  So, I thought an
> extension language was something where you could extend the
> (presumably high level) interpreter with (low level) compiled code.

It could be... 

> But it seems that Lua is more designed for extending the application
> at hand.  That's sort of the opposite of what I do: Lua is for
> extending a low level language with a high level one...  ???

You can use Lua for either task. The point is, lua is a small library
of code which you can easily link into your application. This means
you don't have to ask a user to install python, and you don't have to
support some monstrous set of python modules which you are used to
programming with (Lua only has basic stuff). 

The distinction I usually grab onto is "where is your main loop". 

I have one piece of software where the main loop is in C/C++, because
it's a game, and it needs to be fast. It calls into Lua for tasks like
'asking objects in the world to do things'. That way, I can write the
object code in Lua, and all the hard-coded render loop stuff is in
C/C++ where it's fast. In this case, I have a C program with Lua

I have another piece of software where the C code merely does some
basic program initialization, exports a bunch of functions to lua, and
then runs "init.lua". The Lua code 'runs' the program by calling the
extension functions. In this case, I have a Lua program with C

However, the nice thing about Lua is that it so easily and nicely fits
both roles. Lua dosn't have every feature you might want, but it's
simple enough that you can get it taylored to a task very easily.

David Jeske (N9LCA) + +

       "Whoever thinks a faultless piece to see,
    Thinks what ne'er was, nor is, nor e'er shall be." - Alexander Pope