lua-users home
lua-l archive

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


I'm flummoxed by this one.

My code invokes a Lua function from a C function called from Lua.  The
Lua function updates a global table.  On Linux (Debian Lenny) it works
fine. On MacOS Snow Leopard the update generates a Bus Error.

Linux:
% make -s -B plat=linux && env LUA_CPATH='./?.so' lua tifc.lua
%

MacOS:
% make -s -B plat=macos && env LUA_CPATH='./?.so' lua tifc.lua
Bus error
%

This is with lua 5.1.4.

This code is so simple I must be doing something obviously wrong. Would
someone please point out my error?

ifc.c:
-----------------------------------------------
#include <lua.h>

static int msg( lua_State *L ) { lua_call( L, 0, 0 ); return 0; }

int luaopen_ifc( lua_State *L ) {
    lua_newtable( L );
    lua_pushcfunction(L, msg );
    lua_setfield( L, -2, "msg" );
    return 1;
}
-----------------------------------------------

tifc.lua:
-----------------------------------------------
msg = require( 'ifc' ).msg

foo = {}

function cb( ) foo[#foo+1] = 1 end

msg( cb )
-----------------------------------------------

The Makefile: (invoke as make plat=linux or make plat=macos)

-----------------------------------------------
CFLAGS += -fPIC

LDFLAGS = -llua5.1

ifeq ($(plat),linux)

ifc.so : ifc.o
        gcc -shared  -fPIC -DPIC $< $(LDFLAGS) -o $@

endif

ifeq ($(plat),macos)

ifc.so : ifc.o
        gcc -bundle $< $(LDFLAGS) -ldl -o $@ 

endif
-----------------------------------------------


Thanks!
Diab