void JPLua_Util_ArgAsString( lua_State *L, char *out, int bufsize ) { char *msg; // char *nl; int args = lua_gettop(L); const char *res; int i; // Lets do this a lil different, concat all args and use that as the message ^^ JPLua_Push_ToString( L ); // Ref to tostring (instead of a global lookup, in case someone changes it) for ( i=1; i<=args; i++ ) { lua_pushvalue( L, -1 ); lua_pushvalue( L, i ); lua_call( L, 1, 1 ); // Assume this will never error out res = lua_tostring( L, -1 ); if ( res ) Q_strcat( out, bufsize, res ); lua_pop( L, 1 ); } lua_pop( L, 1 ); msg = out; return; // It's messy but it works :P /* nl = msg; while ( 1 ) { if ( !(*nl) ) { if ( *msg ) { assert( strlen( msg ) < 4096 ); // Failsafe, this should never happen (4096 is engine Com_Printf buffer) return;//Com_Printf( va( "%s\n", msg ) ); } break; } if ( *nl == '\n' ) { // *nl = '\0'; assert( strlen( msg ) < 4096 ); // Failsafe, this should never happen return; /* Com_Printf( va( "%s\n", msg ) ); msg = nl + 1; *nl = '\n'; *//* } nl++; } */ }
void JPLua_Util_ArgAsString( lua_State *L, char *out, int bufsize ) { int args = lua_gettop( L ); const char *res; int i; // Lets do this a lil different, concat all args and use that as the message ^^ JPLua_Push_ToString( L ); // Ref to tostring (instead of a global lookup, in case someone changes it) for ( i = 1; i <= args; i++ ) { lua_pushvalue( L, -1 ); lua_pushvalue( L, i ); lua_call( L, 1, 1 ); // Assume this will never error out res = lua_tostring( L, -1 ); if ( res ) Q_strcat( out, bufsize, res ); lua_pop( L, 1 ); } lua_pop( L, 1 ); return; }