Window events.

This commit is contained in:
jussi
2023-08-18 15:01:58 +03:00
parent c911ba0431
commit 3fc07a02d5
9 changed files with 861 additions and 1112 deletions

1662
API.md

File diff suppressed because it is too large Load Diff

View File

@@ -705,14 +705,22 @@ RL.GLFW_RELEASE=0
RL.GLFW_PRESS=1 RL.GLFW_PRESS=1
RL.GLFW_REPEAT=2 RL.GLFW_REPEAT=2
-- Globals - Event -- Globals - Window
RL.EVENT_KEY=0 RL.EVENT_WINDOW_SIZE=0
RL.EVENT_CHAR=1 RL.EVENT_WINDOW_MAXIMIZE=1
RL.EVENT_MOUSE_BUTTON=2 RL.EVENT_WINDOW_ICONYFY=2
RL.EVENT_MOUSE_CURSOR_POS=3 RL.EVENT_WINDOW_FOCUS=3
RL.EVENT_MOUSE_SCROLL=4 RL.EVENT_WINDOW_DROP=4
RL.EVENT_CURSOR_ENTER=5
-- Globals - Input
RL.EVENT_KEY=5
RL.EVENT_CHAR=6
RL.EVENT_MOUSE_BUTTON=7
RL.EVENT_MOUSE_CURSOR_POS=8
RL.EVENT_MOUSE_SCROLL=9
RL.EVENT_CURSOR_ENTER=10
-- Core - Window -- Core - Window
---Check if window has been initialized successfully ---Check if window has been initialized successfully

View File

@@ -17,9 +17,9 @@ KEY CHANGES:
- ADDED: rlgl Framebuffer management (fbo) functions - ADDED: rlgl Framebuffer management (fbo) functions
- ADDED: rlgl Framebuffer state functions - ADDED: rlgl Framebuffer state functions
- ADDED: rlgl Textures management functions - ADDED: rlgl Textures management functions
- ADDED: Texture and RenderTexture can be given as tables - ADDED: Texture and RenderTexture can be referenced as tables
- ADDED: Camera2D and Camera3D can be given as tables - ADDED: Camera2D and Camera3D can be referenced as tables
- ADDED: Camera2D and Camera3D can be given as tables - ADDED: Camera2D and Camera3D can be referenced as tables
- ADDED: rlgl New defines - ADDED: rlgl New defines
- ADDED: rlgl Textures state functions - ADDED: rlgl Textures state functions
- ADDED: rlgl Some Render batch management functions - ADDED: rlgl Some Render batch management functions
@@ -33,6 +33,7 @@ KEY CHANGES:
- ADDED: rlgl Vertex buffers state. - ADDED: rlgl Vertex buffers state.
- ADDED: rlgl Shader state. - ADDED: rlgl Shader state.
- ADDED: RL.event function with input events. - ADDED: RL.event function with input events.
- ADDED: Window events.
Detailed changes: Detailed changes:
- FIXED: uluaGetRay was looking for integers instead of tables - FIXED: uluaGetRay was looking for integers instead of tables
@@ -96,6 +97,7 @@ Detailed changes:
- ADDED: GetTextureId - ADDED: GetTextureId
- ADDED: ImageDrawCircleLines - ADDED: ImageDrawCircleLines
- ADDED: ImageBlurGaussian - ADDED: ImageBlurGaussian
- ADDED: Values for API.md
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.4.0 Using Raylib 4.2 Release: ReiLua version 0.4.0 Using Raylib 4.2

View File

@@ -1,6 +1,4 @@
Current { Current {
* Events
* Window events
* rlgl * rlgl
* Vertex buffers management * Vertex buffers management
* Matrix state management * Matrix state management
@@ -12,6 +10,7 @@ Backlog {
* New type validators. * New type validators.
* Platformer example physics process for true framerate independence. * Platformer example physics process for true framerate independence.
* Extend color lib functionality. * Extend color lib functionality.
* Global descriptions for API.
* IsWaveReady and other Is* ready functions. * IsWaveReady and other Is* ready functions.
* Text * Text

View File

@@ -105,17 +105,6 @@ apiFile:write( "\n> function RL.event( event )\n\n"..FUNC_DESC.event.."\n\n---\n
apiFile:write( "\n> function RL.log( logLevel, message )\n\n"..FUNC_DESC.log.."\n\n---\n" ) apiFile:write( "\n> function RL.log( logLevel, message )\n\n"..FUNC_DESC.log.."\n\n---\n" )
apiFile:write( "\n> function RL.exit()\n\n"..FUNC_DESC.exit.."\n\n---\n" ) apiFile:write( "\n> function RL.exit()\n\n"..FUNC_DESC.exit.."\n\n---\n" )
-- Events.
apiFile:write( "\n## Events\n" )
apiFile:write( "\nEvent content in RL.event.\n" )
apiFile:write( "\n---\n> { type: RL.EVENT_KEY, int key, int scancode, int action, int mods }\n\n GLFW3 Keyboard Callback, runs on key pressed.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_CHAR, int key }\n\n GLFW3 Char Key Callback, runs on key pressed (get char value).\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_BUTTON, int button, int action, int mods }\n\n GLFW3 Mouse Button Callback, runs on mouse button pressed.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_CURSOR_POS, number x, number y }\n\n GLFW3 Cursor Position Callback, runs on mouse move.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_SCROLL, number xoffset, number yoffset }\n\n GLFW3 Srolling Callback, runs on mouse wheel.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_CURSOR_ENTER, int enter }\n\n GLFW3 Cursor Enter Callback, cursor enters client area.\n\n---\n" )
luaApiFile:write( "-- Put this file into your project folder to provide annotations when using Lua language server.\n\n" ) luaApiFile:write( "-- Put this file into your project folder to provide annotations when using Lua language server.\n\n" )
luaApiFile:write( "RL={}\n\n" ) luaApiFile:write( "RL={}\n\n" )
luaApiFile:write( "-- Functions.\n\n" ) luaApiFile:write( "-- Functions.\n\n" )
@@ -156,21 +145,24 @@ repeat
-- Remove comma from the end. -- Remove comma from the end.
local globalName = lineSplit[2]:sub( 1, -2 ) local globalName = lineSplit[2]:sub( 1, -2 )
apiFile:write( "\n"..globalName.."\n" )
local value = RL[ globalName ] local value = RL[ globalName ]
globalName = "RL."..globalName
globalVariableCount = globalVariableCount + 1 globalVariableCount = globalVariableCount + 1
if value == nil then if value == nil then
luaApiFile:write( globalName.."=nil\n" ) apiFile:write( "\n"..globalName.." = nil\n" )
luaApiFile:write( "RL."..globalName.."=nil\n" )
elseif type( value ) == "table" then elseif type( value ) == "table" then
-- All tables are colors. -- All tables are colors.
luaApiFile:write( globalName.."={" apiFile:write( globalName.." = { "
..math.tointeger( value[1] )..", "..math.tointeger( value[2] )..", "
..math.tointeger( value[3] )..", "..math.tointeger( value[4] ).." }\n" )
luaApiFile:write( "RL."..globalName.."={"
..math.tointeger( value[1] )..","..math.tointeger( value[2] ).."," ..math.tointeger( value[1] )..","..math.tointeger( value[2] )..","
..math.tointeger( value[3] )..","..math.tointeger( value[4] ).."}\n" ) ..math.tointeger( value[3] )..","..math.tointeger( value[4] ).."}\n" )
else else
luaApiFile:write( globalName.."="..value.."\n" ) apiFile:write( globalName.." = "..value.."\n" )
luaApiFile:write( "RL."..globalName.."="..value.."\n" )
end end
end end
end end
@@ -261,6 +253,24 @@ apiFile:write( "\n> NPatchInfo = { { 0, 0, 24, 24 }, 8, 8, 8, 8, NPATCH_NINE_PAT
apiFile:write( "\n> ModelAnimations = ModelAnimationsId\n\ apiFile:write( "\n> ModelAnimations = ModelAnimationsId\n\
int id. ModelAnimations\n\n---\n" ) int id. ModelAnimations\n\n---\n" )
-- Events.
apiFile:write( "\n## Events\n" )
apiFile:write( "\nContent of event table received by RL.event.\n" )
apiFile:write( "\n### Window events\n" )
apiFile:write( "\n---\n> { type: RL.EVENT_WINDOW_SIZE, int width, int height }\n\n WindowSize Callback, runs when window is resized.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_MAXIMIZE, int maximized }\n\n Window Maximize Callback, runs when window is maximized.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_ICONYFY, int iconified }\n\n WindowIconify Callback, runs when window is minimized/restored.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_FOCUS, int focused }\n\n WindowFocus Callback, runs when window get/lose focus.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_DROP, int count, string{} paths }\n\n Window Drop Callback, runs when drop files into window.\n\n---\n" )
apiFile:write( "\n### Input events\n" )
apiFile:write( "\n---\n> { type: RL.EVENT_KEY, int key, int scancode, int action, int mods }\n\n Keyboard Callback, runs on key pressed.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_CHAR, int key }\n\n Char Key Callback, runs on key pressed (get char value).\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_BUTTON, int button, int action, int mods }\n\n Mouse Button Callback, runs on mouse button pressed.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_CURSOR_POS, number x, number y }\n\n Cursor Position Callback, runs on mouse move.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_SCROLL, number xoffset, number yoffset }\n\n Srolling Callback, runs on mouse wheel.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_CURSOR_ENTER, int enter }\n\n Cursor Enter Callback, cursor enters client area.\n\n---\n" )
if separate then if separate then
apiFile:close() apiFile:close()
end end

View File

@@ -4,11 +4,22 @@ local cursorIn = 0
function RL.init() function RL.init()
RL.SetWindowTitle( "Events" ) RL.SetWindowTitle( "Events" )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowState( RL.FLAG_VSYNC_HINT )
end end
local function getEventType( event ) local function getEventType( event )
if event.type == RL.EVENT_KEY then if event.type == RL.EVENT_WINDOW_SIZE then
return "Window Size"
elseif event.type == RL.EVENT_WINDOW_MAXIMIZE then
return "Window Maximized"
elseif event.type == RL.EVENT_WINDOW_ICONYFY then
return "Window Iconyfy"
elseif event.type == RL.EVENT_WINDOW_FOCUS then
return "Window Focus"
elseif event.type == RL.EVENT_WINDOW_DROP then
return "Window Drop"
elseif event.type == RL.EVENT_KEY then
return "Key" return "Key"
elseif event.type == RL.EVENT_CHAR then elseif event.type == RL.EVENT_CHAR then
return "Char" return "Char"
@@ -50,7 +61,20 @@ end
function RL.event( event ) function RL.event( event )
text = "Event: "..getEventType( event ).."\n" text = "Event: "..getEventType( event ).."\n"
if event.type == RL.EVENT_KEY then if event.type == RL.EVENT_WINDOW_SIZE then
text = text.."width: "..event.width.." height: "..event.height
elseif event.type == RL.EVENT_WINDOW_MAXIMIZE then
text = text.."maximized: "..event.maximized
elseif event.type == RL.EVENT_WINDOW_ICONYFY then
text = text.."iconified: "..event.iconified
elseif event.type == RL.EVENT_WINDOW_FOCUS then
text = text.."focused: "..event.focused
elseif event.type == RL.EVENT_WINDOW_DROP then
text = text.."count: "..event.count.."\n"
for _, path in ipairs( event.paths ) do
text = text..path.."\n"
end
elseif event.type == RL.EVENT_KEY then
text = text.."key: "..event.key.." scancode: "..event.scancode.." action: "..getAction( event.action ).." mods: "..event.mods text = text.."key: "..event.key.." scancode: "..event.scancode.." action: "..getAction( event.action ).." mods: "..event.mods
text = text .."\nkeyName: "..keyName( event.key ) text = text .."\nkeyName: "..keyName( event.key )
elseif event.type == RL.EVENT_CHAR then elseif event.type == RL.EVENT_CHAR then
@@ -62,7 +86,7 @@ function RL.event( event )
elseif event.type == RL.EVENT_MOUSE_CURSOR_POS then elseif event.type == RL.EVENT_MOUSE_CURSOR_POS then
text = text.."x: "..event.x.." y: "..event.y text = text.."x: "..event.x.." y: "..event.y
elseif event.type == RL.EVENT_MOUSE_SCROLL then elseif event.type == RL.EVENT_MOUSE_SCROLL then
text = text.."yoffset: "..event.yoffset.." yoffset: "..event.yoffset text = text.."xoffset: "..event.xoffset.." yoffset: "..event.yoffset
elseif event.type == RL.EVENT_CURSOR_ENTER then elseif event.type == RL.EVENT_CURSOR_ENTER then
text = text.."enter: "..event.enter text = text.."enter: "..event.enter
cursorIn = event.enter cursorIn = event.enter

View File

@@ -1,6 +1,18 @@
#pragma once #pragma once
enum EventType { EVENT_KEY, EVENT_CHAR, EVENT_MOUSE_BUTTON, EVENT_MOUSE_CURSOR_POS, EVENT_MOUSE_SCROLL, EVENT_CURSOR_ENTER }; enum EventType {
EVENT_WINDOW_SIZE,
EVENT_WINDOW_MAXIMIZE,
EVENT_WINDOW_ICONYFY,
EVENT_WINDOW_FOCUS,
EVENT_WINDOW_DROP,
EVENT_KEY,
EVENT_CHAR,
EVENT_MOUSE_BUTTON,
EVENT_MOUSE_CURSOR_POS,
EVENT_MOUSE_SCROLL,
EVENT_CURSOR_ENTER
};
void defineGlobals(); void defineGlobals();
void logCustom( int logLevel, const char *text, va_list args ); void logCustom( int logLevel, const char *text, va_list args );

View File

@@ -80,6 +80,13 @@ typedef struct {
size_t lightCount; size_t lightCount;
size_t lightAlloc; size_t lightAlloc;
/* Raylib GLFW input callback events. */ /* Raylib GLFW input callback events. */
/* Window events. */
GLFWwindowsizefun raylibWindowSizeCallback;
GLFWwindowmaximizefun raylibWindowMaximizeCallback;
GLFWwindowiconifyfun raylibWindowIconifyCallback;
GLFWwindowfocusfun raylibWindowFocusCallback;
GLFWdropfun raylibWindowDropCallback;
/* Input events. */
GLFWkeyfun raylibKeyCallback; GLFWkeyfun raylibKeyCallback;
GLFWcharfun raylibCharCallback; GLFWcharfun raylibCharCallback;
GLFWmousebuttonfun raylibMouseButtonCallback; GLFWmousebuttonfun raylibMouseButtonCallback;

View File

@@ -618,7 +618,13 @@ void defineGlobals() {
assignGlobalInt( GLFW_RELEASE, "GLFW_RELEASE" ); assignGlobalInt( GLFW_RELEASE, "GLFW_RELEASE" );
assignGlobalInt( GLFW_PRESS, "GLFW_PRESS" ); assignGlobalInt( GLFW_PRESS, "GLFW_PRESS" );
assignGlobalInt( GLFW_REPEAT, "GLFW_REPEAT" ); assignGlobalInt( GLFW_REPEAT, "GLFW_REPEAT" );
/* Event types. */ /* Window Events. */
assignGlobalInt( EVENT_WINDOW_SIZE, "EVENT_WINDOW_SIZE" );
assignGlobalInt( EVENT_WINDOW_MAXIMIZE, "EVENT_WINDOW_MAXIMIZE" );
assignGlobalInt( EVENT_WINDOW_ICONYFY, "EVENT_WINDOW_ICONYFY" );
assignGlobalInt( EVENT_WINDOW_FOCUS, "EVENT_WINDOW_FOCUS" );
assignGlobalInt( EVENT_WINDOW_DROP, "EVENT_WINDOW_DROP" );
/* Input Events. */
assignGlobalInt( EVENT_KEY, "EVENT_KEY" ); assignGlobalInt( EVENT_KEY, "EVENT_KEY" );
assignGlobalInt( EVENT_CHAR, "EVENT_CHAR" ); assignGlobalInt( EVENT_CHAR, "EVENT_CHAR" );
assignGlobalInt( EVENT_MOUSE_BUTTON, "EVENT_MOUSE_BUTTON" ); assignGlobalInt( EVENT_MOUSE_BUTTON, "EVENT_MOUSE_BUTTON" );
@@ -672,6 +678,159 @@ void logCustom( int logLevel, const char *text, va_list args ) {
lua_pop( L, -1 ); lua_pop( L, -1 );
} }
/* Window events. */
static void windowSizeEvent( GLFWwindow *window, int width, int height ) {
/* Pass through to raylib callback. */
state->raylibWindowSizeCallback( window, width, height );
lua_State *L = state->luaState;
lua_pushcfunction( L, luaTraceback );
int tracebackidx = lua_gettop( L );
lua_getglobal( L, "RL" );
lua_getfield( L, -1, "event" );
if ( lua_isfunction( L, -1 ) ) {
lua_createtable( L, 3, 0 );
lua_pushinteger( L, EVENT_WINDOW_SIZE );
lua_setfield( L, -2, "type" );
lua_pushinteger( L, width );
lua_setfield( L, -2, "width" );
lua_pushinteger( L, height );
lua_setfield( L, -2, "height" );
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false;
}
}
lua_pop( L, -1 );
}
#if !defined( PLATFORM_WEB )
static void windowMaximizeEvent( GLFWwindow *window, int maximized ) {
/* Pass through to raylib callback. */
state->raylibWindowMaximizeCallback( window, maximized );
lua_State *L = state->luaState;
lua_pushcfunction( L, luaTraceback );
int tracebackidx = lua_gettop( L );
lua_getglobal( L, "RL" );
lua_getfield( L, -1, "event" );
if ( lua_isfunction( L, -1 ) ) {
lua_createtable( L, 2, 0 );
lua_pushinteger( L, EVENT_WINDOW_MAXIMIZE );
lua_setfield( L, -2, "type" );
lua_pushinteger( L, maximized );
lua_setfield( L, -2, "maximized" );
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false;
}
}
lua_pop( L, -1 );
}
#endif
static void windowIconyfyEvent( GLFWwindow *window, int iconified ) {
/* Pass through to raylib callback. */
state->raylibWindowIconifyCallback( window, iconified );
lua_State *L = state->luaState;
lua_pushcfunction( L, luaTraceback );
int tracebackidx = lua_gettop( L );
lua_getglobal( L, "RL" );
lua_getfield( L, -1, "event" );
if ( lua_isfunction( L, -1 ) ) {
lua_createtable( L, 2, 0 );
lua_pushinteger( L, EVENT_WINDOW_ICONYFY );
lua_setfield( L, -2, "type" );
lua_pushinteger( L, iconified );
lua_setfield( L, -2, "iconified" );
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false;
}
}
lua_pop( L, -1 );
}
static void windowFocusEvent( GLFWwindow *window, int focused ) {
/* Pass through to raylib callback. */
state->raylibWindowFocusCallback( window, focused );
lua_State *L = state->luaState;
lua_pushcfunction( L, luaTraceback );
int tracebackidx = lua_gettop( L );
lua_getglobal( L, "RL" );
lua_getfield( L, -1, "event" );
if ( lua_isfunction( L, -1 ) ) {
lua_createtable( L, 2, 0 );
lua_pushinteger( L, EVENT_WINDOW_FOCUS );
lua_setfield( L, -2, "type" );
lua_pushinteger( L, focused );
lua_setfield( L, -2, "focused" );
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false;
}
}
lua_pop( L, -1 );
}
static void windowDropEvent( GLFWwindow *window, int count, const char **paths ) {
/* Pass through to raylib callback. */
state->raylibWindowDropCallback( window, count, paths );
lua_State *L = state->luaState;
lua_pushcfunction( L, luaTraceback );
int tracebackidx = lua_gettop( L );
lua_getglobal( L, "RL" );
lua_getfield( L, -1, "event" );
if ( lua_isfunction( L, -1 ) ) {
lua_createtable( L, 3, 0 );
lua_pushinteger( L, EVENT_WINDOW_DROP );
lua_setfield( L, -2, "type" );
lua_pushinteger( L, count );
lua_setfield( L, -2, "count" );
lua_createtable( L, count, 0 );
for ( int i = 0; i < count; ++i ) {
lua_pushstring( L, paths[i] );
lua_rawseti( L, -2, i+1 );
}
lua_setfield( L, -2, "paths" );
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false;
}
}
lua_pop( L, -1 );
}
/* Input events. */
static void keyInputEvent( GLFWwindow* window, int key, int scancode, int action, int mods ) { static void keyInputEvent( GLFWwindow* window, int key, int scancode, int action, int mods ) {
/* Pass through to raylib callback. */ /* Pass through to raylib callback. */
state->raylibKeyCallback( window, key, scancode, action, mods ); state->raylibKeyCallback( window, key, scancode, action, mods );
@@ -700,8 +859,6 @@ static void keyInputEvent( GLFWwindow* window, int key, int scancode, int action
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false; state->run = false;
lua_pop( L, -1 );
return;
} }
} }
lua_pop( L, -1 ); lua_pop( L, -1 );
@@ -729,8 +886,6 @@ static void charInputEvent( GLFWwindow* window, unsigned int key ) {
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false; state->run = false;
lua_pop( L, -1 );
return;
} }
} }
lua_pop( L, -1 ); lua_pop( L, -1 );
@@ -762,8 +917,6 @@ static void mouseButtonInputEvent( GLFWwindow* window, int button, int action, i
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false; state->run = false;
lua_pop( L, -1 );
return;
} }
} }
lua_pop( L, -1 ); lua_pop( L, -1 );
@@ -793,8 +946,6 @@ static void mouseCursorPosInputEvent( GLFWwindow* window, double x, double y ) {
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false; state->run = false;
lua_pop( L, -1 );
return;
} }
} }
lua_pop( L, -1 ); lua_pop( L, -1 );
@@ -824,8 +975,6 @@ static void mouseScrollInputEvent( GLFWwindow* window, double xoffset, double yo
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false; state->run = false;
lua_pop( L, -1 );
return;
} }
} }
lua_pop( L, -1 ); lua_pop( L, -1 );
@@ -853,8 +1002,6 @@ static void cursorEnterInputEvent( GLFWwindow* window, int enter ) {
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false; state->run = false;
lua_pop( L, -1 );
return;
} }
} }
lua_pop( L, -1 ); lua_pop( L, -1 );
@@ -927,6 +1074,16 @@ bool luaCallMain() {
/* Apply custom callback here. */ /* Apply custom callback here. */
SetTraceLogCallback( logCustom ); SetTraceLogCallback( logCustom );
/* Window events. */
state->raylibWindowSizeCallback = glfwSetWindowSizeCallback( GetWindowHandle(), windowSizeEvent );
#if !defined( PLATFORM_WEB )
state->raylibWindowMaximizeCallback = glfwSetWindowMaximizeCallback( GetWindowHandle(), windowMaximizeEvent );
#endif
state->raylibWindowIconifyCallback = glfwSetWindowIconifyCallback( GetWindowHandle(), windowIconyfyEvent );
state->raylibWindowFocusCallback = glfwSetWindowFocusCallback( GetWindowHandle(), windowFocusEvent );
state->raylibWindowDropCallback = glfwSetDropCallback( GetWindowHandle(), windowDropEvent );
/* Input events. */
state->raylibKeyCallback = glfwSetKeyCallback( GetWindowHandle(), keyInputEvent ); state->raylibKeyCallback = glfwSetKeyCallback( GetWindowHandle(), keyInputEvent );
state->raylibCharCallback = glfwSetCharCallback( GetWindowHandle(), charInputEvent ); state->raylibCharCallback = glfwSetCharCallback( GetWindowHandle(), charInputEvent );
state->raylibMouseButtonCallback = glfwSetMouseButtonCallback( GetWindowHandle(), mouseButtonInputEvent ); state->raylibMouseButtonCallback = glfwSetMouseButtonCallback( GetWindowHandle(), mouseButtonInputEvent );