lua-users home
lua-l archive

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


Here is ours
DefineLuaFunction(DebugPrint)
{
	const int LUA_NUM_ARGS = lua_gettop(pState);
	if (LUA_NUM_ARGS == 0) return 0;
	for (int i=1; i<=LUA_NUM_ARGS; i++) {
		int t = lua_type(pState,i);
		const char* tn = lua_typename(pState,t);
		switch ( t ) {
		case LUA_TUSERDATA:
		case LUA_TTABLE: {
			EScriptObject* pScript = Lua_LSOToScriptObject(pState, (const
void*)i, true, true);
			if (pScript) {
				char* pName = "??";
				char* pType = "??";
				pScript->GetTableValue("Name", pName);
				pScript->GetTableValue("Type", pType);
				Trace("%d: %s %s\t(LSO/%s)", i, pType, pName, tn);
			} else {
				Trace("%d: ??\t(%s)", i, tn);
			}
			break;
		}
		case LUA_TNONE:
		case LUA_TNIL:
		case LUA_TNUMBER:
		case LUA_TFUNCTION:
			Trace("%d: %g\t(%s)", i, (float)lua_tonumber(pState, i), tn);
			break;
		case LUA_TSTRING:
			Trace("%d: %s\t(%s)", i, lua_tostring(pState, i), tn);
			break;
		default:
			Trace("%d: invalid type\t(%s)", i, tn?tn:"unknown");
			break;
		}
	}
	return 0;
}



On Wed, 8 Dec 2004 14:47:50 -0800, Philip Plumlee
<phlip@sammystudios.com> wrote:
> Luists:
> 
> Ogle this awesome snip of C++:
> 
>        #define TRACE_(x) cout << #x ": " << x << endl
> 
> When you use that like this...
> 
>        TRACE_(y + z);
>        TRACE_(strAnimals);
>        TRACE_(__LINE__);
> 
> ...the program emits this:
> 
>        y + z: 12
>        strAnimals: Lemmings
>        __LINE__:  69
> 
> Mighty healthy and easy to write debug statements with, huh? Saves a lot
> of keystrokes, huh?
> 
> How do I do that, just as easy to call (meaning without extra "" quotes
> or anything), in Lua?
> 
> --
>   Phlip
>   http://ssw0251/wiki.rb?RecentChanges
>   home: mailto:phlip2005@gmail.com
>   cell: 760 214 2958
>