Lua in game console
I was wondering if it is possible (without modifing the lua source) to have lua send text to your own functions.
What i mean is when you make a lua program setup to run in a windows console and you make a mistake in the lua command it prints the error right to the screen (using printf maybe i dont know).
But what i would like to do is instead of having it printing how ever it does now. Have it print onto my console with in my own game.
quote: From Lua docs.
Because Lua is an extension language, all Lua actions start from C code in the host program calling a function from the Lua library. Whenever an error occurs during Lua compilation or execution, the function _ERRORMESSAGE is called (provided it is different from nil), and then the corresponding function from the library (lua_dofile, lua_dostring, lua_dobuffer, or lua_call) is terminated, returning an error condition.
Memory allocation errors are an exception to the previous rule. When memory allocation fails, Lua may not be able to execute the _ERRORMESSAGE function. So, for this kind of error, Lua does not call the _ERRORMESSAGE function; instead, the corresponding function from the library returns immediately with a special error code (LUA_ERRMEM). This and other error codes are defined in lua.h; Section 5.8.
The only argument to _ERRORMESSAGE is a string describing the error. The default definition for this function calls _ALERT, which prints the message to stderr (see Section 6.1). The standard I/O library redefines _ERRORMESSAGE and uses the debug facilities (see Section 7) to print some extra information, such as a call stack traceback.
Just re-define the function _ERRORMESSAGE(errorstring) to do what you want it to do with the error string.
Josh
vertexnormal AT linuxmail DOT org
Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.
It appers i have forgotten one detail, Im using lua 5.0. After looking in 4.0 documentation i found the quote that you used. Yet it seems to either not be in lua 5.0's documentation or im just not looking well enough. If you do know how to do it with 5.0 please let me know, until then i will be looking through the 5.0 docs for some kind of equivilent funtion.
[edited by - Wolfdog on October 23, 2003 2:26:07 AM]
[edited by - Wolfdog on October 23, 2003 2:26:07 AM]
5.0 does not print error messages by default. Instead, it returns them. Look in the manual for lua_pcall and lua_error, and also the lua functions "pcall" and "error".
How appropriate. You fight like a cow.
How appropriate. You fight like a cow.
In Lua 5.0 redefine "_ALERT", in Lua 4.0 its "_ERRORMESSAGE"
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement