summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2023-10-15 22:31:17 +0300
committerjussi2023-10-15 22:31:17 +0300
commit95be0403e69b3047a0375cf965dedca0ad876409 (patch)
treeebfc72f0e5ad7c193e679a0744443b367902c09a
parent7af7e7003131e182efb30bac8c1ff06ac1d667d6 (diff)
downloadreilua-enhanced-95be0403e69b3047a0375cf965dedca0ad876409.tar.gz
reilua-enhanced-95be0403e69b3047a0375cf965dedca0ad876409.tar.bz2
reilua-enhanced-95be0403e69b3047a0375cf965dedca0ad876409.zip
Argumets stored in RL.arg array.
-rw-r--r--API.md6
-rw-r--r--ReiLua_API.lua2
-rw-r--r--changelog1
-rw-r--r--docgen.lua7
-rw-r--r--include/lua_core.h2
-rw-r--r--include/state.h4
-rw-r--r--src/lua_core.c20
-rw-r--r--src/main.c4
-rw-r--r--src/state.c8
9 files changed, 40 insertions, 14 deletions
diff --git a/API.md b/API.md
index 677c00f..08148d7 100644
--- a/API.md
+++ b/API.md
@@ -1,6 +1,6 @@
# ReiLua API
-## Usage
+## Functions
Application needs 'main.lua' or 'main' file as entry point. ReiLua executable will first look it from same directory. Alternatively, path to the folder where "main.lua" is located can be given as argument. There are five Lua functions that the framework will call, 'RL.init', 'RL.process', 'RL.draw', 'RL.event', 'RL.log', and 'RL.exit'.
@@ -41,6 +41,10 @@ This function will be called on program close. Cleanup could be done here.
---
+## Arguments
+
+Arguments are stored in 'RL.arg' array.
+
## Globals - ConfigFlags
FLAG_VSYNC_HINT = 64
FLAG_FULLSCREEN_MODE = 2
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 66ba45c..881fb11 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -20,6 +20,8 @@ function RL.event( event ) end
function RL.log( logLevel, message ) end
---This function will be called on program close. Cleanup could be done here.
function RL.exit() end
+---This function will be called on program close. Cleanup could be done here.
+function RL.exit() end
-- Globals - ConfigFlags
diff --git a/changelog b/changelog
index 357f4b8..b31f25e 100644
--- a/changelog
+++ b/changelog
@@ -103,6 +103,7 @@ Detailed changes:
- FIXED: isValidRenderTexture checks that it is TEXTURE_TYPE_RENDER_TEXTURE
- FIXED: isValidTexture on CreateMaterial
- CHANGED: Renamed start, end arguments to a, b to avoid using Lua keyword "end" in argument names
+ - ADDED: Argumets stored in "RL.arg" array
------------------------------------------------------------------------
Release: ReiLua version 0.4.0 Using Raylib 4.2
diff --git a/docgen.lua b/docgen.lua
index abfceb1..1927633 100644
--- a/docgen.lua
+++ b/docgen.lua
@@ -86,7 +86,7 @@ apiFile:write( "# ReiLua API\n" )
-- Usage.
-apiFile:write( "\n## Usage\n" )
+apiFile:write( "\n## Functions\n" )
apiFile:write( "\nApplication needs 'main.lua' or 'main' file as entry point. ReiLua executable will first look it from same directory. Alternatively, path to the folder where \"main.lua\" is located can be given as argument. There are five Lua functions that the framework will call, 'RL.init', 'RL.process', 'RL.draw', 'RL.event', 'RL.log', and 'RL.exit'.\n" )
local FUNC_DESC = {
@@ -121,6 +121,11 @@ luaApiFile:write(
"---"..FUNC_DESC.log.."\n---@param logLevel integer\n---@param message string\nfunction RL.log( logLevel, message ) end\n" )
luaApiFile:write(
"---"..FUNC_DESC.exit.."\nfunction RL.exit() end\n" )
+luaApiFile:write(
+"---"..FUNC_DESC.exit.."\nfunction RL.exit() end\n" )
+
+apiFile:write( "\n## Arguments\n" )
+apiFile:write( "\nArguments are stored in 'RL.arg' array.\n" )
-- Globals.
diff --git a/include/lua_core.h b/include/lua_core.h
index 2285ca4..ed5fb7d 100644
--- a/include/lua_core.h
+++ b/include/lua_core.h
@@ -14,7 +14,7 @@ enum EventType {
EVENT_CURSOR_ENTER
};
-bool luaInit();
+bool luaInit( int argn, const char **argc );
int luaTraceback( lua_State *L );
bool luaCallMain();
void luaCallProcess();
diff --git a/include/state.h b/include/state.h
index 13a7c6c..725cb6e 100644
--- a/include/state.h
+++ b/include/state.h
@@ -97,6 +97,6 @@ typedef struct {
extern State *state;
-bool stateInit( const char *exePath );
-void stateInitInterpret();
+bool stateInit( int argn, const char **argc, const char *exePath );
+void stateInitInterpret( int argn, const char **argc );
void stateFree();
diff --git a/src/lua_core.c b/src/lua_core.c
index 15dfe70..c254a9d 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -1007,18 +1007,32 @@ static void cursorEnterInputEvent( GLFWwindow* window, int enter ) {
lua_pop( L, -1 );
}
-bool luaInit() {
+bool luaInit( int argn, const char **argc ) {
state->luaState = luaL_newstate();
+ lua_State *L = state->luaState;
- luaL_openlibs( state->luaState );
+ luaL_openlibs( L );
- if ( state->luaState == NULL ) {
+ if ( L == NULL ) {
TraceLog( LOG_WARNING, "%s", "Failed to init Lua" );
return false;
}
defineGlobals();
+ /* Set arguments. */
+ lua_getglobal( L, "RL" );
+ lua_newtable( L );
+ lua_setfield( L, -2, "arg" );
+ lua_getglobal( L, "RL" );
+ lua_getfield( L, -1, "arg" );
+
+ for ( int i = 0; i < argn; i++ ) {
+ lua_pushstring( L, argc[i] );
+ lua_rawseti( L, -2, i + 1 );
+ }
+ lua_pop( L, -1 );
+
return true;
}
diff --git a/src/main.c b/src/main.c
index 4b90b08..fc64e86 100644
--- a/src/main.c
+++ b/src/main.c
@@ -48,7 +48,7 @@ int main( int argn, const char **argc ) {
}
if ( interpret_mode ) {
- stateInitInterpret();
+ stateInitInterpret( argn, argc );
lua_State *L = state->luaState;
lua_pushcfunction( L, luaTraceback );
@@ -63,7 +63,7 @@ int main( int argn, const char **argc ) {
}
else {
printVersion();
- stateInit( exePath );
+ stateInit( argn, argc, exePath );
luaRegister();
state->run = luaCallMain();
diff --git a/src/state.c b/src/state.c
index 2e1a50f..d1a3329 100644
--- a/src/state.c
+++ b/src/state.c
@@ -6,7 +6,7 @@
State *state;
-bool stateInit( const char *exePath ) {
+bool stateInit( int argn, const char **argc, const char *exePath ) {
state = malloc( sizeof( State ) );
state->exePath = malloc( STRING_LEN * sizeof( char ) );
@@ -107,15 +107,15 @@ bool stateInit( const char *exePath ) {
}
if ( state->run ) {
InitAudioDevice();
- state->run = luaInit();
+ state->run = luaInit( argn, argc );
}
return state->run;
}
-void stateInitInterpret() {
+void stateInitInterpret( int argn, const char **argc ) {
state = malloc( sizeof( State ) );
- luaInit();
+ luaInit( argn, argc );
}
void stateFree() {