lua-users home
lua-l archive

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


On 20/01/2011 05:02, Steve Litt wrote:
In general, when game programmers use C and Lua, to they fire up a C program
that calls a Lua script, or do they fire up a Lua script that calls a C
program, or are both commonly done?

Actually, when you "fire up a Lua script", you run a C program first! It is the first and primary application using Lua, the Lua command line interface calling the Lua interpreter.

I'm glad you responded. In my research I've found no examples of how to start
in Lua and load C modules, nor any documentation of same. Do you know of a
trivial "hello world" application of calling C from Lua for Lua 5.1?

Two ways:
- just recompile the interpreter with your C module, exposing it as as some library (look at I/O module, for example);
- or make a dynamic library to be used with 'require'.

The first one is used by applications scripted with Lua (games, editors...); the second one is used when you want to use the Lua language (interpreter with command line handling) with some added facilities (filesystem, sockets, etc.).

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --