lua-users home
lua-l archive

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

On Friday, February 18, 2011 6:44 AM, Luiz Henrique de Figueiredo wrote:

> I think this has been mentioned here but did you build the host program
> with "-Wl,-E" or equivalent so that the Lua API in the library linked
> in the hos is seen by dynamically loaded modules?

On Friday, February 18, 2011 1:36 AM, Iain Hibbert wrote:

> How do you link with liblua.a?  Using gcc you probably need something
> like -Wl,--whole-archive to make sure that all the functions are linked
> even though they are not referenced at compile time..

Obrigado! That resolves my issue.

In a way I'm glad that I messed up the linkage. It gave me the motivation to go through the lua.c code and now my wrapper code works much better.

To summarize all that I did to get this to work...

I created lua/lib/aes/ with the following functions:
  static int aes_version(lua_State *L) {
    lua_pushstring(L, "20110217");
    return 1;

  int luaopen_aes_core(lua_State *L) {
    const struct luaL_Reg myLibFunctions[] = {
      {"_version", aes_version},
      {0, 0}
    lua_createtable(L, 0, 1);
    luaL_register(L, 0, myLibFunctions);
    return 1;

I use gcc on Redhat Linux, so I compiled the library with -shared -o lua/lib/aes/ to create a shared library.

I created lua/lib/aes.lua with the following:

  local require = require
  local core = require 'aes.core'
  function version()
    return "0.0 - lib = " .. core._version()

I created a test script lua/test/aes.lua:

  require 'aes'
  print("aes version is " .. aes.version())

I set LUA_PATH to include lua/?.lua.

I set LUA_CPATH to include lua/lib/?.so.

I compiled my driver C program with -Wl,-E -lua -lm -ldl.

Running lua/test/aes.lua gives the expected output:

  aes version is 0.0 - lib = 20110217

Thanks again to everyone for their help,