summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md6
-rw-r--r--README.md2
-rw-r--r--doc_parser.lua2
-rw-r--r--examples/snake/main.lua1
-rw-r--r--src/lua_core.c40
-rw-r--r--src/main.c1
6 files changed, 48 insertions, 4 deletions
diff --git a/API.md b/API.md
index 6176e85..434ab4b 100644
--- a/API.md
+++ b/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
KEY_ENTER
diff --git a/README.md b/README.md
index 8833984..8da40ee 100644
--- a/README.md
+++ b/README.md
@@ -17,14 +17,12 @@ List of some MISSING features that are planned to be included. For specific func
* Core
* Some screen-space-related functions
* Files drop
- * custom callbacks
* camera2d and it's functions
* VR stereo config functions for VR simulator
* Textures
* Most image loading functions
* Image manipulation functions
* Texture update functions
- * Color/pixel related functions
* Text
* Some font loading/unloading functions
* Audio
diff --git a/doc_parser.lua b/doc_parser.lua
index 80fa490..8100f49 100644
--- a/doc_parser.lua
+++ b/doc_parser.lua
@@ -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.\
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" )
+apiFile:write( "\n> function log( message )\n\
+This function can be used for custom log message handling.\n\n---\n" )
-- Globals.
diff --git a/examples/snake/main.lua b/examples/snake/main.lua
index 13cff1f..1fe6ae7 100644
--- a/examples/snake/main.lua
+++ b/examples/snake/main.lua
@@ -215,7 +215,6 @@ function draw()
RL_DrawText( 0, "Press Enter to\nrestart", { 10, 10 }, 10, 2, WHITE )
end
RL_EndTextureMode()
-
-- Draw framebuffer to window.
RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE )
diff --git a/src/lua_core.c b/src/lua_core.c
index 55e0fda..ece4c97 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -204,6 +204,44 @@ void defineGlobals() {
/*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() {
state->luaState = luaL_newstate();
@@ -284,6 +322,8 @@ bool luaCallMain() {
TraceLog( LOG_WARNING, "%s", "No Lua main found!" );
return false;
}
+ /* Apply custom callback here. */
+ SetTraceLogCallback( LogCustom );
return true;
}
diff --git a/src/main.c b/src/main.c
index cd060d4..9bb5d2e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -18,7 +18,6 @@ int main( int argn, const char **argc ) {
else {
sprintf( exePath, "%s/", GetWorkingDirectory() );
}
-
TraceLog( LOG_INFO, "ReiLua %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
stateInit( exePath );