lua-users home
lua-l archive

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


Wim Couwenberg wrote:

If I do 'lua_dofile' and the file contains errors
(like syntax errors), lua returns and on my stack
there is one element (a table).

Better not use lua_dofile.  It is `compatibilty code'
for Lua 4 compatibility and depends on a global _ALERT
function.  In Lua 5 it's much nicer to use
luaL_loadfile (from lauxlib.h).  It leaves an error
message (a string) on top of stack if something goes
wrong.  Here's an example:

int my_dofile(lua_State *L, int nresults, const char
*name)
{
	/* load script */
	int rc = luaL_loadfile(L, name);
	if (rc)
		/* compile time error message on tos */
		return rc;

	/* execute script. Leaves error message on tos
	   in case of a run-time error */
	return lua_pcall(L, 0, nresults, 0);
}

See luaB_dofile (the implementation of `dofile' in the
base lib) in lbaselib.c for another example

http://www.lua.org/source/5.0/src_lib_lbaselib.c.html#luaB_dofile

--
Wim


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com


it works

thank you,
mark