summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2022-02-20 20:37:39 +0200
committerjussi2022-02-20 20:37:39 +0200
commit8182a5f1b6c61bdf95d32a4ad102e1762f0d0924 (patch)
treedea5baa7433161c1eb00277ae186b99fee940a1f
parent6e4fdd3b3ae4e4656e151f098c40cfe551a36e8c (diff)
downloadreilua-enhanced-8182a5f1b6c61bdf95d32a4ad102e1762f0d0924.tar.gz
reilua-enhanced-8182a5f1b6c61bdf95d32a4ad102e1762f0d0924.tar.bz2
reilua-enhanced-8182a5f1b6c61bdf95d32a4ad102e1762f0d0924.zip
Documentation and better cmakelist.
-rw-r--r--.gitignore3
-rw-r--r--API.md3
-rw-r--r--CMakeLists.txt31
-rw-r--r--README.md133
-rw-r--r--devnotes3
-rw-r--r--doc_parser.lua3
-rw-r--r--examples/window/main.lua23
-rw-r--r--include/main.h28
-rw-r--r--src/rmath.c41
9 files changed, 229 insertions, 39 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ed1936d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.vscode
+Toolchain-mingw32.cmake
+releases \ No newline at end of file
diff --git a/API.md b/API.md
index caa9303..84764c6 100644
--- a/API.md
+++ b/API.md
@@ -2,8 +2,7 @@
## Usage
-Application needs 'main.lua' file as entry point. ReiLua executable will first look it from same directory
-or it's path can be given by argument. There are three global functions that the engine will call, 'init', 'process' and 'draw'.
+Application needs 'main.lua' 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 three global Lua functions that the engine will call, 'init', 'process' and 'draw'.
---
> function init()
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 33fe7a5..32c1737 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,39 +1,36 @@
cmake_minimum_required( VERSION 3.15 )
project( ReiLua )
-# find_package( raylib 3.7 REQUIRED ) # Requires at least version 3.7
-
-set( CMAKE_C_STANDARD 11 ) # Requires C11 standard
+set( CMAKE_C_STANDARD 99 ) # Requires C99 standard
if( UNIX )
set( CMAKE_C_COMPILER "gcc" )
elseif( APPLE )
set( CMAKE_C_COMPILER "clang" )
+# elseif( WIN32 )
+# set( CMAKE_C_COMPILER "mingw32" )
endif()
-set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb -std=c11 -Wall -pedantic -fno-common" )
-# set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=c11 -Wall -pedantic -fno-common" )
-
-option( STATIC ON )
-option( DRM OFF )
+# set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb -std=c99 -Wall -pedantic -fno-common" )
+set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=c99 -Wall -pedantic -fno-common" )
include_directories( include )
file( GLOB SOURCES "src/*.c" )
add_executable( ${PROJECT_NAME} ${SOURCES} )
-if( STATIC )
- message( Static )
- target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/libraylib.a )
- target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/liblua.a )
-else()
- find_package( raylib 4.0 REQUIRED ) # Requires at least version 4.0
+if( SHARED )
message( Shared )
+ find_package( raylib 4.0 REQUIRED ) # Requires at least version 4.0
target_link_libraries( ${PROJECT_NAME} raylib )
target_link_libraries( ${PROJECT_NAME} lua )
+else()
+ message( Static )
+ target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/libraylib.a )
+ target_link_libraries( ${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/liblua.a )
endif()
if( UNIX )
- if( DRM ) # Raspberry pi
+ if( DRM ) # Mainly for Raspberry pi
# target_link_libraries( ${PROJECT_NAME} GLESv2 EGL drm gbm rt bcm_host m dl pthread )
target_link_libraries( ${PROJECT_NAME} GLESv2 EGL drm gbm rt m dl pthread )
else()
@@ -41,6 +38,10 @@ if( UNIX )
endif()
endif()
+if( WIN32 )
+ target_link_libraries( ${PROJECT_NAME} mingw32 opengl32 gdi32 winmm )
+endif()
+
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
if( APPLE )
target_link_libraries( ${PROJECT_NAME} "-framework IOKit" )
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b76bdf3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,133 @@
+## About
+
+Idea of this project was to bring the power and simplicity of raylib to easy beginner friendly language like Lua in a very straight forward manner. It is not a straight binding to Raylib, some functions are not included and some are added. The idea of pointing "main.lua" file and access functions "init", "process" and "draw" are borrowed from Löve game engine.
+
+Need for boilerplate code is minimal and in true Lua fashion (in better and worse) you don't need to worry about types and typecasts since all Raylib types are just lua tables and object id's. Also what Lua cannot handle, the engine is simple enough to be fairly easily extended with new functionality or by using Lua C-libraries.
+
+## Status
+
+Engine is currently in arbitrary version 0.1 and some functionality is still missing. Also the build system is still lacking of Web build and Mac is not tested.
+
+## Usage
+
+Application needs 'main.lua' 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 three global Lua functions that the engine will call, 'init', 'process' and 'draw'.
+
+Example of basic "main.lua" file that will show basic windows with text.
+
+```
+local textColor = BLACK
+local textPos = { 192, 200 }
+
+function init()
+ RL_SetWindowTitle( "First window" )
+end
+
+function process( delta )
+ if RL_IsKeyPressed( KEY_ENTER ) then
+ textColor = BLUE
+ textPos = { 230, 230 }
+ end
+
+ if RL_IsKeyPressed( KEY_SPACE ) then
+ textColor = BLACK
+ textPos = { 192, 200 }
+ end
+end
+
+function draw()
+ RL_ClearBackground( RAYWHITE );
+ RL_DrawText( 0, "Congrats! You created your first window!", textPos, 20, 2, textColor );
+end
+```
+
+Application folder structure should be...
+
+```
+GameFolder
+ \ReiLua.exe
+ \main.lua
+```
+
+Application should now start successfully from executable. All functionality can be found in "API".
+
+## Building
+
+I think the simplest way would be to statically link Raylib and Lua to the same executable. Specially on Linux this would simplify distribution of games since different distros tend to use different versions of librarys. Of course if you plan to only experiment with it, this isn't so important. At the time of writing ReiLua uses latest Raylib version from master branch. If you use Raylib v4.0.0 release, you will get a lot of undefined reference errors.
+
+//TODO In future these instructions should be set on fixed release versions of Raylib.
+
+https://github.com/raysan5/raylib
+https://github.com/lua/lua
+
+### Linux
+
+Compile Raylib and lua by following their instructions. They will compile to libraylib.a and liblua.a by default.
+
+You need build essential and cmake. If you compiled Raylib you should already have these.
+
+```
+sudo apt install build-essential
+sudo apt install cmake
+```
+
+If compiling statically, move libraylib.a and liblua.a to "ReiLua/lib" folder. From "ReiLua" folder...
+
+```
+cd build
+cmake ..
+make
+```
+
+Run example.
+
+```
+./ReiLua ../examples/snake/
+```
+
+If you now see extremely low res snake racing off the window then you are successfull. Congratulations! You can reset the game by pressing enter.
+
+### Windows
+
+I don't have much experience on compiling on Windows, but I got the following method to work.
+
+* Download "w64devkit" from https://github.com/skeeto/w64devkit and "CMake" from https://cmake.org/download/. Install CMake with path environment variables set.
+* Download Raylib source.
+* Run "w64devkit.exe" and navigate( ls == dir ) to "raylib-master/src" folder and run...
+
+```
+mingw32-make
+```
+
+* You should now have "libraylib.a" file in that folder.
+* Copy that to "ReiLua/lib" folder.
+* I haven't got Lua to compile on Windows so we will download it's binarys from http://luabinaries.sourceforge.net/download.html. Take the one with "Windows x64 DLL and Includes (MingW-w64 6 Built)".
+* Copy "liblua54.a" to "ReiLua/lib" folder.
+* Change it's name to "liblua.a" or change the part in "CMakeLists.txt" where it links to "/lib/liblua.a" to "/lib/liblua54.a".
+* Navigate to "ReiLua/build" folder with "w64devkit" and run...
+
+```
+cmake -G "MinGW Makefiles" ..
+
+# Cmake uses NMake Makefiles by default so we will set the Generator to MinGW with -G
+
+mingw32-make
+```
+
+* You should now have "ReiLua.exe".
+* From Lua folder, copy "lua54.dll" to same folder with "ReiLua.exe". Don't change the name of it!
+
+Run example.
+
+```
+./ReiLua.exe ../examples/snake/
+```
+
+If you now see extremely low res snake racing off the window then you are successfull. Congratulations! You can reset the game by pressing enter.
+
+### MacOS
+
+Not tested, but I guess it should work similarly to Linux.
+
+### Raspberry Pi
+
+Works best when compiled using PLATFORM=DRM, but Raylib seems to have some problems with the input handling.
diff --git a/devnotes b/devnotes
index 20aece2..162bd45 100644
--- a/devnotes
+++ b/devnotes
@@ -1,8 +1,9 @@
Backlog {
* Compilation
* Windows
+ Mingw cross compilation causes name clashes with raylib https://github.com/raysan5/raylib/issues/1217
* Web
- * Could be better in general
+ * Better CMakeList
* More and better examples
* Raygui
diff --git a/doc_parser.lua b/doc_parser.lua
index dafedb3..6c74b02 100644
--- a/doc_parser.lua
+++ b/doc_parser.lua
@@ -22,8 +22,7 @@ apiFile:write( "# ReiLua API\n" )
-- Usage.
apiFile:write( "\n## Usage\n" )
-apiFile:write( "\nApplication needs 'main.lua' file as entry point. ReiLua executable will first look it from same directory\
-or it's path can be given by argument. There are three global functions that the engine will call, 'init', 'process' and 'draw'.\n" )
+apiFile:write( "\nApplication needs 'main.lua' 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 three global Lua functions that the engine will call, 'init', 'process' and 'draw'.\n" )
apiFile:write( "\n---\n> function init()\n\
This function will be called first when 'main.lua' is found\n\n---\n" )
diff --git a/examples/window/main.lua b/examples/window/main.lua
new file mode 100644
index 0000000..d49d96a
--- /dev/null
+++ b/examples/window/main.lua
@@ -0,0 +1,23 @@
+local textColor = BLACK
+local textPos = { 192, 200 }
+
+function init()
+ RL_SetWindowTitle( "First window" )
+end
+
+function process( delta )
+ if RL_IsKeyPressed( KEY_ENTER ) then
+ textColor = BLUE
+ textPos = { 230, 230 }
+ end
+
+ if RL_IsKeyPressed( KEY_SPACE ) then
+ textColor = BLACK
+ textPos = { 192, 200 }
+ end
+end
+
+function draw()
+ RL_ClearBackground( RAYWHITE );
+ RL_DrawText( 0, "Congrats! You created your first window!", textPos, 20, 2, textColor );
+end
diff --git a/include/main.h b/include/main.h
index 43b0a4c..64b2578 100644
--- a/include/main.h
+++ b/include/main.h
@@ -5,6 +5,24 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
+// #define WIN32_LEAN_AND_MEAN
+// #if defined(_WIN32)
+// #define WIN32
+// #endif
+// #if defined(_WIN64)
+// #define WIN64
+// #define _AMD64_
+// #undef _X86_
+// #else
+// #undef _AMD64_
+// #define _X86_
+// #endif
+
+// #include <minwindef.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -14,3 +32,13 @@
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
+
+#include <stdint.h>
+
+// #ifdef _WIN32
+// // #include <windows.h>
+// #include <windef.h>
+// #include <mmsystem.h>
+// // #include <winbase.h>
+// // #define APIENTRY WINAPI
+// #endif
diff --git a/src/rmath.c b/src/rmath.c
index 7ad9bdb..4027aa8 100644
--- a/src/rmath.c
+++ b/src/rmath.c
@@ -889,14 +889,15 @@ int lmathMatrixFrustum( lua_State *L ) {
lua_pushboolean( L, false );
return 1;
}
- float far = lua_tonumber( L, -1 );
- float near = lua_tonumber( L, -2 );
- float top = lua_tonumber( L, -3 );
- float bottom = lua_tonumber( L, -4 );
- float right = lua_tonumber( L, -5 );
- float left = lua_tonumber( L, -6 );
+ // float far = lua_tonumber( L, -1 );
+ // float near = lua_tonumber( L, -2 );
+ // float top = lua_tonumber( L, -3 );
+ // float bottom = lua_tonumber( L, -4 );
+ // float right = lua_tonumber( L, -5 );
+ // float left = lua_tonumber( L, -6 );
- uluaPushMatrix( L, MatrixFrustum( left, right, bottom, top, near, far ) );
+ // uluaPushMatrix( L, MatrixFrustum( left, right, bottom, top, near, far ) );
+ uluaPushMatrix( L, MatrixFrustum( lua_tonumber( L, -6 ), lua_tonumber( L, -5 ), lua_tonumber( L, -4 ), lua_tonumber( L, -3 ), lua_tonumber( L, -2 ), lua_tonumber( L, -1 ) ) );
return 1;
}
@@ -915,12 +916,13 @@ int lmathMatrixPerspective( lua_State *L ) {
lua_pushboolean( L, false );
return 1;
}
- float far = lua_tonumber( L, -1 );
- float near = lua_tonumber( L, -2 );
- float aspect = lua_tonumber( L, -3 );
- float fovy = lua_tonumber( L, -4 );
+ // float far = lua_tonumber( L, -1 );
+ // float near = lua_tonumber( L, -2 );
+ // float aspect = lua_tonumber( L, -3 );
+ // float fovy = lua_tonumber( L, -4 );
- uluaPushMatrix( L, MatrixPerspective( fovy, aspect, near, far ) );
+ // uluaPushMatrix( L, MatrixPerspective( fovy, aspect, near, far ) );
+ uluaPushMatrix( L, MatrixPerspective( lua_tonumber( L, -4 ), lua_tonumber( L, -3 ), lua_tonumber( L, -2 ), lua_tonumber( L, -1 ) ) );
return 1;
}
@@ -940,14 +942,15 @@ int lmathMatrixOrtho( lua_State *L ) {
lua_pushboolean( L, false );
return 1;
}
- float far = lua_tonumber( L, -1 );
- float near = lua_tonumber( L, -2 );
- float top = lua_tonumber( L, -3 );
- float bottom = lua_tonumber( L, -4 );
- float right = lua_tonumber( L, -5 );
- float left = lua_tonumber( L, -6 );
+ // float far = lua_tonumber( L, -1 );
+ // float near = lua_tonumber( L, -2 );
+ // float top = lua_tonumber( L, -3 );
+ // float bottom = lua_tonumber( L, -4 );
+ // float right = lua_tonumber( L, -5 );
+ // float left = lua_tonumber( L, -6 );
- uluaPushMatrix( L, MatrixOrtho( left, right, bottom, top, near, far ) );
+ // uluaPushMatrix( L, MatrixOrtho( left, right, bottom, top, near, far ) );
+ uluaPushMatrix( L, MatrixOrtho( lua_tonumber( L, -6 ), lua_tonumber( L, -5 ), lua_tonumber( L, -4 ), lua_tonumber( L, -3 ), lua_tonumber( L, -2 ), lua_tonumber( L, -1 ) ) );
return 1;
}