lua-users home
lua-l archive

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


Dear Lua people,

I'm trying to put together a small (68K) Mac C application, using
lualib31_68K and CodeWarrior 11. I managed to execute some plain Lua
scripts, but I also need to write a few new functions in C, to be called
from Lua. However, when I launch my application and the luaL_openlib(...)
gets executed, I get:

   "API error - attempt to push a NULL Cfunction"

I'd be glad if anybody could suggest what I'm doing wrong. This is how my
"ezlualib.c" file looks:


char *rcs_ezlualib = "$Id: ezlualib.c,v 0.9 1998/11/12 21:12:00 jon Exp $";

#include <stdlib.h>
#ifndef __MACTCP__
#include <MacTCP.h>
#endif

#include "lualib.h"
#include "lauxlib.h"
#include "lua.h"
#include "eztcp.h"

static void ez_IPNameToAddr (void)
{
        OSErr   err;
        ip_addr addr;

        err = IPNameToAddress( luaL_check_string(1), &addr );
        if (err != noErr) {
                addr = 0;
        }
        lua_pushnumber( addr );
}

static void ez_Button (void)
{
        if (Button()) lua_pushnumber(1);
}

static void ez_SysBeep (void)
{
        SysBeep( luaL_check_number(1) );
}

static struct luaL_reg ezlualib[] = {
        {"IPNameToAddr", ez_IPNameToAddr},
        {"Button",  ez_Button},
        {"SysBeep", ez_SysBeep}
};

void ezlualib_open (void);
void ezlualib_open (void)
{
        luaL_openlib(ezlualib, (sizeof(ezlualib)/sizeof(ezlualib[0])));
}

------------

Sincerely,

Jon Kleiser