tags:

views:

84

answers:

1

Hi,

I am trying to load the example lproc program (described on Programming Lua, Chapter 30) into Lua and fouling up somehow. I am following this - http://www.lua.org/pil/26.2.html to get my c module into lua. Following are the steps that I've taken:

  1. I have an lproc.h and lproc.c (containing exactly the functions laid out in Chapter 30 of the book). I am compiling lproc.c as --- gcc -c lproc.c -DLUA-USERCONFIG=\"lproc.h\"

  2. I made a library out of lproc.o, named the same.

  3. And then compiled lua.c as instructed. My header files contain the macro LUA_EXTRALIBS and the method declarations.

  4. Went to the Lua interpreter and it gave the following errors:

> require "lproc"
stdin:1: module 'lproc' not found:
    no field package.preload['lproc']
    no file './lproc.lua'
    no file '/opt/local/share/lua/5.1/lproc.lua'
    no file '/opt/local/share/lua/5.1/lproc/init.lua'
    no file '/opt/local/lib/lua/5.1/lproc.lua'
    no file '/opt/local/lib/lua/5.1/lproc/init.lua'
    no file './lproc.so'
    no file '/opt/local/lib/lua/5.1/lproc.so'
    no file '/opt/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    stdin:1: in main chunk
    [C]: ?

It seems that the module did not get registered, what would I need to do from Lua? Time is short and I am doing something horrendously wrong, any direction would be welcome.

Thanks,
Sayan

+3  A: 

The easiest way is to create a shared library and load your C module dynamically. This way avoids having to rebuild the Lua interpreter. There are several examples in http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/ and explanations in http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html and http://lua-users.org/wiki/BuildingModules

lhf
Thanks I would try them out!
Sayan