Custom log function.
This commit is contained in:
6
API.md
6
API.md
@@ -25,6 +25,12 @@ You can still use RL_BeginDrawing() and RL_EndDrawing() manually from anywhere.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
> function log( message )
|
||||||
|
|
||||||
|
This function can be used for custom log message handling.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Globals - Keys
|
## Globals - Keys
|
||||||
|
|
||||||
KEY_ENTER
|
KEY_ENTER
|
||||||
|
|||||||
@@ -17,14 +17,12 @@ List of some MISSING features that are planned to be included. For specific func
|
|||||||
* Core
|
* Core
|
||||||
* Some screen-space-related functions
|
* Some screen-space-related functions
|
||||||
* Files drop
|
* Files drop
|
||||||
* custom callbacks
|
|
||||||
* camera2d and it's functions
|
* camera2d and it's functions
|
||||||
* VR stereo config functions for VR simulator
|
* VR stereo config functions for VR simulator
|
||||||
* Textures
|
* Textures
|
||||||
* Most image loading functions
|
* Most image loading functions
|
||||||
* Image manipulation functions
|
* Image manipulation functions
|
||||||
* Texture update functions
|
* Texture update functions
|
||||||
* Color/pixel related functions
|
|
||||||
* Text
|
* Text
|
||||||
* Some font loading/unloading functions
|
* Some font loading/unloading functions
|
||||||
* Audio
|
* Audio
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ apiFile:write( "\n> function draw()\n\
|
|||||||
This function will be called every frame after process and it should have all rendering related functions.\
|
This function will be called every frame after process and it should have all rendering related functions.\
|
||||||
Note: Engine will call Raylib functions 'BeginDrawing()' before this function call and 'EndDrawing()' after it.\
|
Note: Engine will call Raylib functions 'BeginDrawing()' before this function call and 'EndDrawing()' after it.\
|
||||||
You can still use RL_BeginDrawing() and RL_EndDrawing() manually from anywhere.\n\n---\n" )
|
You can still use RL_BeginDrawing() and RL_EndDrawing() manually from anywhere.\n\n---\n" )
|
||||||
|
apiFile:write( "\n> function log( message )\n\
|
||||||
|
This function can be used for custom log message handling.\n\n---\n" )
|
||||||
|
|
||||||
-- Globals.
|
-- Globals.
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,6 @@ function draw()
|
|||||||
end
|
end
|
||||||
RL_EndTextureMode()
|
RL_EndTextureMode()
|
||||||
|
|
||||||
|
|
||||||
-- Draw framebuffer to window.
|
-- Draw framebuffer to window.
|
||||||
RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE )
|
RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE )
|
||||||
RL_DrawTexturePro( framebuffer, { 0, 0, RESOLUTION[1], -RESOLUTION[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE )
|
RL_DrawTexturePro( framebuffer, { 0, 0, RESOLUTION[1], -RESOLUTION[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE )
|
||||||
|
|||||||
@@ -204,6 +204,44 @@ void defineGlobals() {
|
|||||||
/*DOC_END*/
|
/*DOC_END*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Custom logging funtion
|
||||||
|
void LogCustom( int msgType, const char *text, va_list args ) {
|
||||||
|
char string[ STRING_LEN ] = {'\0'};
|
||||||
|
char msg[ STRING_LEN ] = {'\0'};
|
||||||
|
|
||||||
|
vsprintf( string, text, args );
|
||||||
|
|
||||||
|
switch ( msgType ) {
|
||||||
|
case LOG_ALL: sprintf( msg, "ALL: %s", string ); break;
|
||||||
|
case LOG_TRACE: sprintf( msg, "TRACE: %s", string ); break;
|
||||||
|
case LOG_DEBUG: sprintf( msg, "DEBUG: %s", string ); break;
|
||||||
|
case LOG_INFO: sprintf( msg, "INFO: %s", string ); break;
|
||||||
|
case LOG_WARNING: sprintf( msg, "WARNING: %s", string ); break;
|
||||||
|
case LOG_ERROR: sprintf( msg, "ERROR: %s", string ); break;
|
||||||
|
case LOG_FATAL: sprintf( msg, "FATAL: %s", string ); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
printf( "%s\n", msg );
|
||||||
|
|
||||||
|
/* Call Lua log function if exists. */
|
||||||
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
|
lua_pushcfunction( L, luaTraceback );
|
||||||
|
int tracebackidx = lua_gettop( L );
|
||||||
|
lua_getglobal( L, "log" );
|
||||||
|
|
||||||
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
|
lua_pushstring( L, msg );
|
||||||
|
|
||||||
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
|
TraceLog( LOG_WARNING, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
|
state->run = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lua_pop( L, -1 );
|
||||||
|
}
|
||||||
|
|
||||||
bool luaInit() {
|
bool luaInit() {
|
||||||
state->luaState = luaL_newstate();
|
state->luaState = luaL_newstate();
|
||||||
|
|
||||||
@@ -284,6 +322,8 @@ bool luaCallMain() {
|
|||||||
TraceLog( LOG_WARNING, "%s", "No Lua main found!" );
|
TraceLog( LOG_WARNING, "%s", "No Lua main found!" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/* Apply custom callback here. */
|
||||||
|
SetTraceLogCallback( LogCustom );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ int main( int argn, const char **argc ) {
|
|||||||
else {
|
else {
|
||||||
sprintf( exePath, "%s/", GetWorkingDirectory() );
|
sprintf( exePath, "%s/", GetWorkingDirectory() );
|
||||||
}
|
}
|
||||||
|
|
||||||
TraceLog( LOG_INFO, "ReiLua %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
|
TraceLog( LOG_INFO, "ReiLua %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
|
||||||
stateInit( exePath );
|
stateInit( exePath );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user