[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Help needed calling Lua from my C function
- From: Mike Crowe <mikelocal@...>
- Date: Thu, 14 Apr 2005 15:14:51 -0400
Hi folks,
I'm using 5.1work5 embedded in my application (just starting,
actually). I was following somebody's directions that I can no longer find.
Can somebody tell me what I'm doing wrong? The error function myError
doesn't get called.
static int myError (lua_State *L) {
char *d = lua_touserdata(L, -1);
const char *p;
lua_pop(L,1); /* upvalue */
if ( lua_isstring(L,1) ) {
p = lua_tostring(L,1);
printf(p);
}
return 0; /* number of results */
}
int main (void) {
lua_State *L=lua_open();
luaopen_base(L);
luaopen_string(L); // opens the string lib.
luaopen_table(L);
luaopen_math(L);
luaopen_io(L);
luaopen_avalon_pio(L);
luaopen_bit(L);
luapush_globals(L);
lua_pushcfunction(L,myError);
lua_setglobal(L,"_ALERT");
if ( lua_mylua(L) ) // lua_mylua() is the
do_buffer of the compiled object code.
printf( "Lua Error\n" );
lua_close(L);
return(0);
}