Added initial files.

This commit is contained in:
jussi
2022-02-18 18:27:10 +02:00
parent 345cc1d5aa
commit 6e4fdd3b3a
53 changed files with 27310 additions and 0 deletions

27
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,27 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/ReiLua",
"args": ["/examples/font/"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

2955
API.md Normal file

File diff suppressed because it is too large Load Diff

49
CMakeLists.txt Normal file
View File

@@ -0,0 +1,49 @@
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
if( UNIX )
set( CMAKE_C_COMPILER "gcc" )
elseif( APPLE )
set( CMAKE_C_COMPILER "clang" )
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 )
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
message( Shared )
target_link_libraries( ${PROJECT_NAME} raylib )
target_link_libraries( ${PROJECT_NAME} lua )
endif()
if( UNIX )
if( DRM ) # 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()
target_link_libraries( ${PROJECT_NAME} m dl pthread )
endif()
endif()
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
if( APPLE )
target_link_libraries( ${PROJECT_NAME} "-framework IOKit" )
target_link_libraries( ${PROJECT_NAME} "-framework Cocoa" )
target_link_libraries( ${PROJECT_NAME} "-framework OpenGL" )
endif()

5
build/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
CMakeCache.txt
cmake_install.cmake
Makefile
CMakeFiles
ReiLua

27
devnotes Normal file
View File

@@ -0,0 +1,27 @@
Backlog {
* Compilation
* Windows
* Web
* Could be better in general
* More and better examples
* Raygui
* Advanced controls
* Core
* File drop
* Screen-space-related
* Cursor-related
* Text
* Fonts
* More draw functions
* Codepoints
* String management. At least TextSplit
* Audio
* Wave?
* Gestures
* Raymath
* Quaternions
* Physac
* VR?
}

171
doc_parser.lua Normal file
View File

@@ -0,0 +1,171 @@
--Create api.md file from c sources.
local function split( str, sep )
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch( str, "([^"..sep.."]+)" ) do
table.insert( t, str )
end
return t
end
local apiFile = io.open( "API.md", "w" )
-- Header
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( "\n---\n> function init()\n\
This function will be called first when 'main.lua' is found\n\n---\n" )
apiFile:write( "\n> function process( delta )\n\
This function will be called every frame during execution. It will get time duration from last frame on argument 'delta'\n\n---\n" )
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\n\n---\n" )
-- Globals.
local srcFile = io.open( "src/lua_core.c", "r" )
local writing = false
repeat
line = srcFile:read( "*l" )
local lineSplit = split( line, " " )
if line == "/*DOC_END*/" then
writing = false
break
end
if writing then
if lineSplit[1] == "\t/*" then
apiFile:write( "\n## Globals - "..lineSplit[2].."\n" )
else
-- Remove comma from the end.
apiFile:write( "\n"..lineSplit[2]:sub( 1, -2 ).."\n" )
end
end
if line == "/*DOC_START*/" then
writing = true
end
until line == nil
srcFile:close()
-- Types.
apiFile:write( "\n## Types\n\
Raylib structs in Lua\n\n---\n" )
apiFile:write( "\n> Vector2 = { 1.0, 1.0 }\n\
Vector2 type\n\n---\n" )
apiFile:write( "\n> Vector3 = { 1.0, 1.0, 1.0 }\n\
Vector3 type\n\n---\n" )
apiFile:write( "\n> Vector4 = { 1.0, 1.0, 1.0, 1.0 }\n\
Vector4 type\n\n---\n" )
apiFile:write( "\n> Quaternion = { 1.0, 1.0, 1.0, 1.0 }\n\
Quaternion type\n\n---\n" )
apiFile:write( "\n> Matrix = { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0 } }\n\
OpenGL style 4x4. Identity matrix example\n\n---\n" )
apiFile:write( "\n> Color = { 255, 255, 255, 255 }\n\
{ r, g, b ,a }. Color type, RGBA (32bit)\n\n---\n" )
apiFile:write( "\n> Rectangle = { 0.0, 0.0, 1.0, 1.0 }\n\
{ x, y, w ,h }. Rectangle type\n\n---\n" )
apiFile:write( "\n> Image = ImageId\n\
int id. Image type (multiple pixel formats supported). NOTE: Data stored in CPU memory (RAM)\n\n---\n" )
apiFile:write( "\n> Texture = TextureId\n\
int id. Texture type (multiple internal formats supported). NOTE: Data stored in GPU memory (VRAM)\n\n---\n" )
apiFile:write( "\n> RenderTexture = RenderTextureId\n\
int id. RenderTexture type, for texture rendering\n\n---\n" )
apiFile:write( "\n> Font = FontId\n\
int id. Font type, includes texture and chars data\n\n---\n" )
apiFile:write( "\n> Camera = CameraId\n\
int id. Defines 3d camera position/orientation\n\n---\n" )
apiFile:write( "\n> Mesh = MeshId\n\
int id. Vertex data defining a mesh\n\n---\n" )
apiFile:write( "\n> Material = MaterialId\n\
int id. Material type\n\
```\
table = {\
shader = Shader,\
maps = {\
{\
MATERIAL_MAP_ALBEDO,\
{\
texture = Texture,\
color = WHITE,\
value = 1.0,\
},\
},\
...\
},\
params = { 1.0, 2.0, 3.0, 4.0 },\
}\
```\n\n---\n" )
apiFile:write( "\n> Model = ModelId\n\
int id. Basic 3d Model type\n\n---\n" )
apiFile:write( "\n> Ray = { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } }\n\
{ position, direction }. Ray type (useful for raycast)\n\n---\n" )
apiFile:write( "\n> RayCollision = { hit = true, distance = 1.0, point = { 0.0, 0.0 }, normal = { 0.0, 0.0, 1.0 } }\n\
Raycast hit information. NOTE: Data in named keys\n\n---\n" )
apiFile:write( "\n> BoundingBox = { { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } }\n\
{ min, max }. Bounding box type for 3d mesh\n\n---\n" )
apiFile:write( "\n> Sound = SoundId\n\
int id. Basic Sound source and buffer\n\n---\n" )
apiFile:write( "\n> NPatchInfo = { { 0, 0, 24, 24 }, 0, 0, 0, 0, NPATCH_NINE_PATCH }\n\
{ Rectangle source, int left, int top, int right, int bottom, int layout }.\
{ Texture source rectangle, Left border offset, Top border offset, Right border offset, Bottom border offset, Layout of the n-patch: 3x3, 1x3 or 3x1 }\n\n---\n" )
apiFile:write( "\n> ModelAnimations = ModelAnimationsId\n\
int id. ModelAnimations\n\n---\n" )
-- Functions.
local sourceFiles = {
"src/core.c",
"src/shapes.c",
"src/textures.c",
"src/text.c",
"src/models.c",
"src/audio.c",
"src/rmath.c",
"src/rgui.c",
}
for _, src in ipairs( sourceFiles ) do
srcFile = io.open( src, "r" )
local line = ""
local p = false
repeat
line = srcFile:read( "*l" )
if line == "*/" then
p = false
apiFile:write( "\n---\n" )
end
if p then
apiFile:write( line.."\n" )
end
if line == "/*" then
p = true
apiFile:write( "\n" )
end
until line == nil
srcFile:close()
end
apiFile:close()

View File

@@ -0,0 +1,147 @@
local pos = { 2, 0.5, 6 }
local speed = 5.0
local camera = -1
local texture = -1
local mesh = -1
local textureSize = { 128, 128 }
local res = { 384, 216 }
local winSize = RL_GetWindowSize()
local winScale = 5
local framebuffer = -1
local TILE_SIZE = 32
local COLOR_WHITE = { 255, 255, 255 }
local FLOOR = 1
local CEILING = 2
local WALL_N = 3
local WALL_S = 4
local WALL_W = 5
local WALL_E = 6
local sprites = {
{ pos = { 0.5, 0.5 }, tile = { 0, 1 }, dis = 0, size = 0.7 },
{ pos = { 3.5, 0.5 }, tile = { 0, 1 }, dis = 0, size = 0.7 },
}
local function getTexCoords( x, y )
return {
{ x * TILE_SIZE / textureSize[1], y * TILE_SIZE / textureSize[2] },
{ x * TILE_SIZE / textureSize[1], ( y * TILE_SIZE + TILE_SIZE ) / textureSize[2] },
{ ( x * TILE_SIZE + TILE_SIZE ) / textureSize[1], ( y * TILE_SIZE + TILE_SIZE ) / textureSize[2] },
{ ( x * TILE_SIZE + TILE_SIZE ) / textureSize[1], y * TILE_SIZE / textureSize[2] },
}
end
local function getTileVer( x, y, type )
local types = {
{ { 0, 0, 0 }, { 0, 0, 1 }, { 1, 0, 1 }, { 1, 0, 0 } }, -- Floor.
{ { 1, 1, 0 }, { 1, 1, 1 }, { 0, 1, 1 }, { 0, 1, 0 } }, -- Ceiling.
{ { 0, 1, 0 }, { 0, 0, 0 }, { 1, 0, 0 }, { 1, 1, 0 } }, -- Wall North.
{ { 1, 1, 1 }, { 1, 0, 1 }, { 0, 0, 1 }, { 0, 1, 1 } }, -- Wall South.
{ { 0, 1, 1 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 1, 0 } }, -- Wall West.
{ { 1, 1, 0 }, { 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 1 } }, -- Wall East.
}
local verts = types[ type ]
for i = 1, 4 do
verts[i][1] = verts[i][1] + x
verts[i][3] = verts[i][3] + y
end
return verts
end
function drawSprites()
for _, sprite in ipairs( sprites ) do
sprite.dis = RL_Vector2Distance( { pos[1], pos[3] }, { sprite.pos[1], sprite.pos[2] } )
end
table.sort( sprites, function( a, b ) return a.dis > b.dis end )
for _, sprite in ipairs( sprites ) do
RL_DrawBillboardRec( camera, texture, { sprite.tile[1] * TILE_SIZE, sprite.tile[2] * TILE_SIZE, TILE_SIZE, TILE_SIZE },
{ sprite.pos[1], 0.5 * sprite.size, sprite.pos[2] }, { sprite.size, sprite.size }, COLOR_WHITE )
end
end
function init()
local monitor = 0
local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor )
-- RL_SetWindowSize( { 1920, 1080 } )
winSize = { res[1] * winScale, res[2] * winScale }
-- winSize = { 1920, 1080 }
RL_SetWindowSize( winSize )
RL_SetExitKey( KEY_ESCAPE )
-- framebuffer = RL_LoadRenderTexture( res )
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" )
camera = RL_CreateCamera3D()
mesh = RL_GenMeshCube( { 1, 2, 1 } )
RL_SetCamera3DPosition( camera, pos )
RL_SetCamera3DTarget( camera, { 0, 0, 0 } )
RL_SetCamera3DUp( camera, { 0, 1, 0 } )
RL_SetCamera3DMode( camera, CAMERA_FIRST_PERSON )
-- RL_SetCamera3DMode( camera, CAMERA_ORBITAL )
-- for x = 0, 3 do
-- for y = 0, 9 do
-- table.insert( sprites, { pos = { x + 0.5, y + 0.5 + 1 }, tile = { 1, 1 }, dis = 0, size = 0.8 } )
-- end
-- end
table.insert( sprites, { pos = { 2.5, 2.5 }, tile = { 1, 1 }, dis = 0, size = 0.8 } )
-- for x = 0, 1 do
-- for y = 0, 1 do
-- table.insert( sprites, { pos = { 1.25 + x * 0.5, 2.25 + y * 0.5 }, tile = { 3, 0 }, dis = 0, size = 0.6 } )
-- end
-- end
table.insert( sprites, { pos = { 1.5, 3.5 }, tile = { 3, 1 }, dis = 0, size = 0.5 } )
table.insert( sprites, { pos = { 0.5, 3.5 }, tile = { 3, 0 }, dis = 0, size = 0.7 } )
end
function process( delta )
-- RL_SetCamera3DPosition( camera, pos )
end
function draw()
RL_UpdateCamera3D( camera )
pos = RL_GetCamera3DPosition( camera )
-- RL_BeginTextureMode( framebuffer )
RL_ClearBackground( { 100, 150, 150 } )
RL_BeginMode3D( camera )
-- Floor and ceiling.
for x = 0, 3 do
for y = 0, 10 do
RL_DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), COLOR_WHITE )
end
end
-- Walls.
RL_DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), COLOR_WHITE )
for x = 0, 3 do
RL_DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), COLOR_WHITE )
end
for y = 0, 10 do
RL_DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), COLOR_WHITE )
RL_DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), COLOR_WHITE )
end
drawSprites()
RL_EndMode3D()
-- RL_EndTextureMode()
-- RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE )
-- RL_DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, COLOR_WHITE )
-- RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE )
end

70
examples/gui/main.lua Normal file
View File

@@ -0,0 +1,70 @@
local windowOpen = true
local toggled = false
local checkbox = false
local textBoxText = "Edit"
local textBoxActive = false
local spinnerValue = 3
local spinnerActive = false
local spinnerValueRange = { 0, 10 }
local sliderValue = 5.0
local sliderValueRange = { 0.0, 10.0 }
local scrollbarValue = 0.0
local dropdownValue = 0
local dropdownActive = false
function init()
local monitor = 0
local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor )
local winSize = RL_GetWindowSize()
RL_GuiSetFont( 0 )
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
end
function process( delta )
end
function draw()
RL_ClearBackground( { 50, 20, 75 } )
if RL_GuiButton( { 112, 16, 96, 32 }, "Button" ) then
print( "Button pressed!" )
end
if windowOpen and RL_GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) then
windowOpen = false
end
RL_GuiPanel( { 60, 260, 100, 100 } )
toggled = RL_GuiToggle( { 200, 260, 64, 32 }, "Toggle", toggled )
checkbox = RL_GuiCheckBox( { 200, 300, 16, 16 }, "CheckBox", checkbox )
local textBoxToggle = false
textBoxToggle, textBoxText = RL_GuiTextBox( { 32, 400, 120, 32 }, textBoxText, 32, textBoxActive )
-- textBoxToggle, textBoxText = RL_GuiTextBoxMulti( { 32, 400, 120, 64 }, textBoxText, 120, textBoxActive )
if textBoxToggle then
textBoxActive = not textBoxActive
end
local spinnerToggle = false
spinnerToggle, spinnerValue = RL_GuiSpinner( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive )
-- spinnerToggle, spinnerValue = RL_GuiValueBox( { 64, 450, 96, 32 }, "Value", spinnerValue, spinnerValueRange[1], spinnerValueRange[2], spinnerActive )
if spinnerToggle then
spinnerActive = not spinnerActive
end
sliderValue = RL_GuiSliderBar( { 64, 510, 96, 32 }, "min", "max", sliderValue, sliderValueRange[1], sliderValueRange[2] )
scrollbarValue = RL_GuiScrollBar( { 64, 550, 130, 32 }, scrollbarValue, 0, 10 )
local dropdownToggle = false
dropdownToggle, dropdownValue = RL_GuiDropdownBox( { 2, 2, 96, 16 }, "Cat\nDog\nMonkey", dropdownValue, dropdownActive )
if dropdownToggle then
dropdownActive = not dropdownActive
end
end

View File

@@ -0,0 +1,30 @@
local monitor = 0
local texture = -1
local image = -1
local catImage = -1
function init()
local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor )
local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
image = RL_GenImageColor( winSize[1], winSize[2], WHITE )
catImage = RL_LoadImage( RL_GetBasePath().."../resources/images/cat.png" )
RL_ImageClearBackground( image, { 150, 60, 100 } )
RL_ImageDrawPixel( image, { 32, 32 }, WHITE )
RL_ImageDrawLine( image, { 32, 45 }, { 100, 60 }, GREEN )
RL_ImageDrawCircle( image, { 64, 32 }, 16, BLUE )
RL_ImageDrawRectangle( image, { 120, 64, 32, 64 }, BLUE )
RL_ImageDrawRectangleLines( image, { 160, 64, 32, 64 }, 2.0, BLUE )
RL_ImageDraw( image, catImage, { 143, 25, 230, 250 }, { 200, 200, 230, 250 }, WHITE )
RL_ImageDrawTextEx( image, 0, "Hello", { 300, 32 }, 48.0, 1.0, WHITE )
texture = RL_LoadTextureFromImage( image )
end
function draw()
RL_ClearBackground( { 100, 150, 100 } )
RL_DrawTexture( texture, { 0, 0 }, WHITE )
end

View File

@@ -0,0 +1,55 @@
local tex = -1
local pos = { 32, 32 }
local speed = 60.0
local sound = -1
local monitor = 0
local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor )
local framebuffer = -1
local res = { 320, 180 }
local scale = 5
local winSize = { res[1] * scale, res[2] * scale }
function init()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
RL_SetWindowSize( winSize )
tex = RL_LoadTexture( RL_GetBasePath().."../resources/images/cat.png" )
-- Create framebuffer.
framebuffer = RL_LoadRenderTexture( res )
end
function process( delta )
if RL_IsKeyDown( KEY_RIGHT ) then
pos[1] = pos[1] + delta * speed
elseif RL_IsKeyDown( KEY_LEFT ) then
pos[1] = pos[1] - delta * speed
end
if RL_IsKeyDown( KEY_UP ) then
pos[2] = pos[2] - delta * speed
elseif RL_IsKeyDown( KEY_DOWN ) then
pos[2] = pos[2] + delta * speed
end
if RL_IsWindowResized() then
winSize = RL_GetWindowSize()
end
end
function draw()
RL_ClearBackground( { 0, 0, 0 } )
RL_BeginTextureMode( framebuffer )
RL_ClearBackground( { 100, 150, 100 } )
RL_DrawPixel( { 100, 100 }, { 255, 50, 100 } )
RL_DrawLine( { 120, 100 }, { 140, 150 }, 2.4, { 255, 150, 255 } )
RL_DrawRectangle( { 200, 120, 40, 50 }, { 100, 170, 255 } )
RL_DrawTexturePro( tex, { 166, 138, 128, 128 }, { pos[1], pos[2], 128, 128 }, { 16, 16 }, 0.0, WHITE )
RL_DrawText( 0, "Cat MIAU!!", { 16, 32 }, 10, 1, { 255, 180, 155 } )
RL_EndTextureMode()
RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE )
RL_DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, { 255, 255, 255 } )
RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE )
end

47
examples/ray/main.lua Normal file
View File

@@ -0,0 +1,47 @@
local camera = -1
local sphereMesh = -1
local ray = { { 0.5, 0, 4 }, { 0.1, 0, -1 } }
local function setupWindow()
local monitor = 0
local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor )
local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
end
function init()
setupWindow()
camera = RL_CreateCamera3D()
RL_SetCamera3DPosition( camera, { 0, 2, 4 } )
RL_SetCamera3DTarget( camera, { 0, 0, 0 } )
RL_SetCamera3DUp( camera, { 0, 2, 0 } )
RL_SetCamera3DMode( camera, CAMERA_FREE )
sphereMesh = RL_GenMeshSphere( 1.0, 8, 10 )
-- local rayCol = RL_GetRayCollisionSphere( { { 0.5, 0, 4 }, { 0, 0, -1 } }, { 0, 0, 0 }, 1.0 )
local rayCol = RL_GetRayCollisionMesh( ray, sphereMesh, RL_MatrixIdentity() )
if rayCol ~= nil and rayCol.hit then
print( "hit", rayCol.hit )
print( "distance", rayCol.distance )
print( "point", rayCol.point[1], rayCol.point[2], rayCol.point[3] )
print( "normal", rayCol.normal[1], rayCol.normal[2], rayCol.normal[3] )
end
end
function draw()
RL_ClearBackground( { 100, 150, 100 } )
RL_UpdateCamera3D( camera )
RL_BeginMode3D( camera )
RL_DrawGrid( 8, 1 )
RL_DrawRay( ray, { 255, 100, 100 } )
RL_DrawMesh( sphereMesh, 0, RL_MatrixIdentity() )
RL_EndMode3D()
end

View File

@@ -0,0 +1,5 @@
Resource Author Licence Source
tiles.png Chris Hamons (maintainer) CC0 https://opengameart.org/content/dungeon-crawl-32x32-tiles
apple.png Jussi Viitala CC0
grass.png Jussi Viitala CC0
snake.png Jussi Viitala CC0

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -0,0 +1,36 @@
#version 100
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
uniform float secondes;
uniform vec2 size;
uniform float freqX;
uniform float freqY;
uniform float ampX;
uniform float ampY;
uniform float speedX;
uniform float speedY;
void main() {
float pixelWidth = 1.0 / size.x;
float pixelHeight = 1.0 / size.y;
float aspect = pixelHeight / pixelWidth;
float boxLeft = 0.0;
float boxTop = 0.0;
vec2 p = fragTexCoord;
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
gl_FragColor = texture2D(texture0, p)*colDiffuse*fragColor;
}

View File

@@ -0,0 +1,37 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// Output fragment color
out vec4 finalColor;
uniform float secondes;
uniform vec2 size;
uniform float freqX;
uniform float freqY;
uniform float ampX;
uniform float ampY;
uniform float speedX;
uniform float speedY;
void main() {
float pixelWidth = 1.0 / size.x;
float pixelHeight = 1.0 / size.y;
float aspect = pixelHeight / pixelWidth;
float boxLeft = 0.0;
float boxTop = 0.0;
vec2 p = fragTexCoord;
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;
finalColor = texture(texture0, p)*colDiffuse*fragColor;
}

60
examples/shaders/main.lua Normal file
View File

@@ -0,0 +1,60 @@
local monitor = 0
local shader = -1
local texture = -1
local textureSize
local GLSL_VERSION = "330" -- PLATFORM_DESKTOP
-- local GLSL_VERSION = "100" -- PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
local secondsLoc
function init()
local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor )
local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/cat.png" )
textureSize = RL_GetTextureSize( texture )
shader = RL_LoadShader( nil, RL_GetBasePath().."../resources/shaders/glsl"..GLSL_VERSION.."/wave.fs" )
secondsLoc = RL_GetShaderLocation( shader, "secondes" )
local sizeLoc = RL_GetShaderLocation( shader, "size" )
local freqXLoc = RL_GetShaderLocation( shader, "freqX" )
local freqYLoc = RL_GetShaderLocation( shader, "freqY" )
local ampXLoc = RL_GetShaderLocation( shader, "ampX" )
local ampYLoc = RL_GetShaderLocation( shader, "ampY" )
local speedXLoc = RL_GetShaderLocation( shader, "speedX" )
local speedYLoc = RL_GetShaderLocation( shader, "speedY" )
local freqX = 25.0
local freqY = 25.0
local ampX = 5.0
local ampY = 5.0
local speedX = 8.0
local speedY = 8.0
RL_SetShaderValue( shader, sizeLoc, textureSize, SHADER_UNIFORM_VEC2 )
RL_SetShaderValue( shader, freqXLoc, { freqX }, SHADER_UNIFORM_FLOAT )
RL_SetShaderValue( shader, freqYLoc, { freqY }, SHADER_UNIFORM_FLOAT )
RL_SetShaderValue( shader, ampXLoc, { ampX }, SHADER_UNIFORM_FLOAT )
RL_SetShaderValue( shader, ampYLoc, { ampY }, SHADER_UNIFORM_FLOAT )
RL_SetShaderValue( shader, speedXLoc, { speedX }, SHADER_UNIFORM_FLOAT )
RL_SetShaderValue( shader, speedYLoc, { speedY }, SHADER_UNIFORM_FLOAT )
end
local seconds = 0.0
function draw()
seconds = seconds + RL_GetFrameTime();
RL_SetShaderValue( shader, secondsLoc, { seconds }, SHADER_UNIFORM_FLOAT );
RL_ClearBackground( { 100, 150, 100 } )
RL_BeginShaderMode( shader )
RL_DrawTexture( texture, { 0, 0 }, WHITE );
RL_EndShaderMode()
end

219
examples/snake/main.lua Normal file
View File

@@ -0,0 +1,219 @@
-- Defines
local RESOLUTION = { 128, 128 }
local TILE_SIZE = 8
local LEVEL_SIZE = RESOLUTION[1] / TILE_SIZE
local STATE = { TITLE = 0, GAME = 1, OVER = 2 } -- Enum wannabe.
-- Resources
local framebuffer = -1
local monitor = 0
local monitorPos = RL_GetMonitorPosition( monitor )
local monitorSize = RL_GetMonitorSize( monitor )
local winScale = 6
local winSize = { RESOLUTION[1] * winScale, RESOLUTION[2] * winScale }
local gameState = STATE.GAME
local grassTexture = -1
local snakeTexture = -1
local appleTexture = -1
local gameSpeed = 7.0
local moveTimer = 1.0
local snake = {}
local applePos = {}
local function setSnake()
snake = {
heading = { 1, 0 },
control = { 1, 0 },
headPos = { LEVEL_SIZE / 2, LEVEL_SIZE / 2 },
segments = {},
grow = 2,
}
end
local function vector2IsEqual( v1, v2 )
return v1[1] == v2[1] and v1[2] == v2[2]
end
local function addSegment()
-- If first segment, grow from head and otherwise from tail. New segments are inserted firts.
if #snake.segments == 0 then
table.insert( snake.segments, 1, { pos = snake.headPos, heading = snake.heading } )
else
table.insert( snake.segments, 1, { pos = snake.segments[ #snake.segments ].pos,
heading = snake.segments[ #snake.segments ].heading } )
end
end
local function setApplePos()
applePos = { math.random( 0, LEVEL_SIZE - 1 ), math.random( 0, LEVEL_SIZE - 1 ) }
local search = true
while search do
search = false
applePos = { math.random( 0, LEVEL_SIZE - 1 ), math.random( 0, LEVEL_SIZE - 1 ) }
for _, seg in ipairs( snake.segments ) do
search = vector2IsEqual( applePos, seg.pos )
if search then
break
end
end
end
end
-- Init.
function init()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowSize( winSize )
RL_SetWindowPosition( { monitorPos[1] + monitorSize[1] / 2 - winSize[1] / 2, monitorPos[2] + monitorSize[2] / 2 - winSize[2] / 2 } )
RL_SetWindowTitle( "Snake" )
RL_SetWindowIcon( RL_LoadImage( RL_GetBasePath().."../resources/images/apple.png" ) )
framebuffer = RL_LoadRenderTexture( RESOLUTION )
grassTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/grass.png" )
snakeTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/snake.png" )
appleTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/apple.png" )
setSnake()
setApplePos()
end
-- Process.
local function moveSnake()
-- Check if snake has eaten and should grow.
if 0 < snake.grow then
addSegment()
snake.grow = snake.grow - 1
end
-- Move body.
for i, seg in ipairs( snake.segments ) do
if i < #snake.segments then
seg.pos = snake.segments[ i+1 ].pos
seg.heading = snake.segments[ i+1 ].heading
else
seg.pos = snake.headPos
seg.heading = snake.heading
end
end
-- Move head.
snake.heading = { snake.control[1], snake.control[2] }
snake.headPos = { snake.headPos[1] + snake.heading[1], snake.headPos[2] + snake.heading[2] }
-- Check appple eating.
if vector2IsEqual( snake.headPos, applePos ) then
snake.grow = snake.grow + 1
setApplePos()
end
-- Check if hit to body.
for _, seg in ipairs( snake.segments ) do
if vector2IsEqual( snake.headPos, seg.pos ) then
gameState = STATE.OVER
end
end
-- Check if outside or level.
if snake.headPos[1] < 0 or LEVEL_SIZE <= snake.headPos[1] or snake.headPos[2] < 0 or LEVEL_SIZE <= snake.headPos[2] then
gameState = STATE.OVER
end
moveTimer = moveTimer + 1.0
end
function process( delta )
if gameState == STATE.GAME then -- Run game.
-- Controls.
if RL_IsKeyPressed( KEY_RIGHT ) and 0 <= snake.heading[1] then
snake.control = { 1, 0 }
elseif RL_IsKeyPressed( KEY_LEFT ) and snake.heading[1] <= 0 then
snake.control = { -1, 0 }
elseif RL_IsKeyPressed( KEY_DOWN ) and 0 <= snake.heading[2] then
snake.control = { 0, 1 }
elseif RL_IsKeyPressed( KEY_UP ) and snake.heading[2] <= 0 then
snake.control = { 0, -1 }
end
moveTimer = moveTimer - gameSpeed * delta
if moveTimer <= 0.0 then
moveSnake()
end
elseif gameState == STATE.OVER and RL_IsKeyPressed( KEY_ENTER ) then -- Reset game.
setSnake()
setApplePos()
gameState = STATE.GAME
end
end
-- Drawing.
local function drawGrass()
for y = 0, LEVEL_SIZE - 1 do
for x = 0, LEVEL_SIZE - 1 do
RL_DrawTexture( grassTexture, { x * TILE_SIZE, y * TILE_SIZE }, WHITE )
end
end
end
--[[ Check if next segment is on left side. There are more mathematically elegant solution to this, but there is
only four possibilities so we can just check them all. ]]--
local function onLeft( this, next )
return ( vector2IsEqual( this, { 0, -1 } ) and vector2IsEqual( next, { -1, 0 } ) )
or ( vector2IsEqual( this, { -1, 0 } ) and vector2IsEqual( next, { 0, 1 } ) )
or ( vector2IsEqual( this, { 0, 1 } ) and vector2IsEqual( next, { 1, 0 } ) )
or ( vector2IsEqual( this, { 1, 0 } ) and vector2IsEqual( next, { 0, -1 } ) )
end
local function drawSnake()
for i, seg in ipairs( snake.segments ) do
local angle = math.deg( RL_Vector2Angle( { 0, 0 }, seg.heading ) )
local source = { 16, 0, 8, 8 }
if i == 1 then -- Tail segment. Yes tail is actually the 'first' segment.
source[1] = 8
if 1 < #snake.segments then
angle = math.deg( RL_Vector2Angle( { 0, 0 }, snake.segments[ 2 ].heading ) )
end
elseif i < #snake.segments and not vector2IsEqual( seg.heading, snake.segments[ i+1 ].heading ) then -- Turned middle segments.
source[1] = 0
-- Mirror turned segment to other way.
if onLeft( seg.heading, snake.segments[ i+1 ].heading ) then
source[4] = -8
end
elseif i == #snake.segments and not vector2IsEqual( seg.heading, snake.heading ) then -- Turned segment before head.
source[1] = 0
if onLeft( seg.heading, snake.heading ) then
source[4] = -8
end
end
-- Notice that we set the origin to center { 4, 4 } that acts as pivot point. We also have to adjust our dest position by 4.
RL_DrawTexturePro( snakeTexture, source, { seg.pos[1] * TILE_SIZE + 4, seg.pos[2] * TILE_SIZE + 4, 8, 8 }, { 4, 4 }, angle, WHITE )
end
-- Let's draw the head last to keep it on top.
local angle = math.deg( RL_Vector2Angle( { 0, 0 }, snake.heading ) )
RL_DrawTexturePro( snakeTexture, { 24, 0, 8, 8 }, { snake.headPos[1] * TILE_SIZE + 4, snake.headPos[2] * TILE_SIZE + 4, 8, 8 }, { 4, 4 }, angle, WHITE )
end
local function drawApple()
RL_DrawTexture( appleTexture, { applePos[1] * TILE_SIZE, applePos[2] * TILE_SIZE }, WHITE )
end
function draw()
-- Clear the window to black.
RL_ClearBackground( BLACK )
-- Draw to framebuffer.
RL_BeginTextureMode( framebuffer )
RL_ClearBackground( BLACK )
drawGrass()
drawSnake()
drawApple()
RL_EndTextureMode()
-- Draw framebuffer to window.
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_SetTextureSource( TEXTURE_SOURCE_TEXTURE )
end

16
include/audio.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
/* Sounds. */
int laudioLoadSound( lua_State *L );
int laudioPlaySoundMulti( lua_State *L );
int laudioSetSoundVolume( lua_State *L );
int laudioSetSoundPitch( lua_State *L );
int laudioUnloadSound( lua_State *L );
/* Music. */
int laudioLoadMusicStream( lua_State *L );
int laudioPlayMusicStream( lua_State *L );
int laudioStopMusicStream( lua_State *L );
int laudioPauseMusicStream( lua_State *L );
int laudioResumeMusicStream( lua_State *L );
int laudioIsMusicStreamPlaying( lua_State *L );
int laudioSetMusicVolume( lua_State *L );

101
include/core.h Normal file
View File

@@ -0,0 +1,101 @@
#pragma once
/* Validators. */
bool validCamera3D( size_t id );
/* Window. */
int lcoreSetWindowMonitor( lua_State *L );
int lcoreSetWindowPosition( lua_State *L );
int lcoreSetWindowSize( lua_State *L );
int lcoreGetMonitorPosition( lua_State *L );
int lcoreGetMonitorSize( lua_State *L );
int lcoreGetWindowPosition( lua_State *L );
int lcoreGetWindowSize( lua_State *L );
int lcoreSetWindowState( lua_State *L );
int lcoreIsWindowState( lua_State *L );
int lcoreClearWindowState( lua_State *L );
int lcoreIsWindowResized( lua_State *L );
int lcoreSetWindowIcon( lua_State *L );
int lcoreSetWindowTitle( lua_State *L );
/* Timing. */
int lcoreSetTargetFPS( lua_State *L );
int lcoreGetFrameTime( lua_State *L );
int lcoreGetTime( lua_State *L );
/* Misc. */
int lcoreTraceLog( lua_State *L );
int lcoreOpenURL( lua_State *L );
/* Cursor. */
int lcoreShowCursor( lua_State *L );
int lcoreHideCursor( lua_State *L );
int lcoreIsCursorHidden( lua_State *L );
int lcoreEnableCursor( lua_State *L );
int lcoreDisableCursor( lua_State *L );
int lcoreIsCursorOnScreen( lua_State *L );
/* Drawing. */
int lcoreClearBackground( lua_State *L );
int lcoreBeginBlendMode( lua_State *L );
int lcoreEndBlendMode( lua_State *L );
int lcoreBeginScissorMode( lua_State *L );
int lcoreEndScissorMode( lua_State *L );
/* Shader. */
int lcoreLoadShader( lua_State *L );
int lcoreLoadShaderFromMemory( lua_State *L );
int lcoreBeginShaderMode( lua_State *L );
int lcoreEndShaderMode( lua_State *L );
int lcoreGetShaderLocation( lua_State *L );
int lcoreGetShaderLocationAttrib( lua_State *L );
int lcoreSetShaderValueMatrix( lua_State *L );
int lcoreSetShaderValueTexture( lua_State *L );
int lcoreSetShaderValue( lua_State *L );
int lcoreSetShaderValueV( lua_State *L );
int lcoreUnloadShader( lua_State *L );
/* File. */
int lcoreGetBasePath( lua_State *L );
int lcoreFileExists( lua_State *L );
int lcoreDirectoryExists( lua_State *L );
int lcoreIsFileExtension( lua_State *L );
int lcoreGetFileExtension( lua_State *L );
int lcoreGetFileName( lua_State *L );
int lcoreGetFileNameWithoutExt( lua_State *L );
int lcoreGetDirectoryPath( lua_State *L );
int lcoreGetPrevDirectoryPath( lua_State *L );
int lcoreGetWorkingDirectory( lua_State *L );
int lcoreGetDirectoryFiles( lua_State *L );
int lcoreGetFileModTime( lua_State *L );
/* Camera. */
int lcoreCreateCamera3D( lua_State *L );
int lcoreUnloadCamera3D( lua_State *L );
int lcoreBeginMode3D( lua_State *L );
int lcoreEndMode3D( lua_State *L );
int lcoreSetCamera3DPosition( lua_State *L );
int lcoreSetCamera3DTarget( lua_State *L );
int lcoreSetCamera3DUp( lua_State *L );
int lcoreSetCamera3DFovy( lua_State *L );
int lcoreSetCamera3DProjection( lua_State *L );
int lcoreGetCamera3DPosition( lua_State *L );
int lcoreGetCamera3DTarget( lua_State *L );
int lcoreGetCamera3DUp( lua_State *L );
int lcoreGetCamera3DFovy( lua_State *L );
int lcoreGetCamera3DProjection( lua_State *L );
int lcoreUpdateCamera3D( lua_State *L );
int lcoreSetCamera3DMode( lua_State *L );
/* Input. */
int lcoreIsKeyPressed( lua_State *L );
int lcoreIsKeyDown( lua_State *L );
int lcoreIsKeyReleased( lua_State *L );
int lcoreGetKeyPressed( lua_State *L );
int lcoreGetCharPressed( lua_State *L );
int lcoreSetExitKey( lua_State *L );
int lcoreIsGamepadAvailable( lua_State *L );
int lcoreIsGamepadButtonPressed( lua_State *L );
int lcoreIsGamepadButtonDown( lua_State *L );
int lcoreIsGamepadButtonReleased( lua_State *L );
int lcoreGetGamepadAxisCount( lua_State *L );
int lcoreGetGamepadAxisMovement( lua_State *L );
int lcoreGetGamepadName( lua_State *L );
int lcoreIsMouseButtonPressed( lua_State *L );
int lcoreIsMouseButtonDown( lua_State *L );
int lcoreIsMouseButtonReleased( lua_State *L );
int lcoreGetMousePosition( lua_State *L );
int lcoreGetMouseDelta( lua_State *L );
int lcoreGetMouseWheelMove( lua_State *L );
int lcoreSetMousePosition( lua_State *L );

24
include/lapi.h Normal file
View File

@@ -0,0 +1,24 @@
/*
** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
*/
#ifndef lapi_h
#define lapi_h
#include "llimits.h"
#include "lstate.h"
#define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
"stack overflow");}
#define adjustresults(L,nres) \
{ if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
"not enough elements in the stack")
#endif

264
include/lauxlib.h Normal file
View File

@@ -0,0 +1,264 @@
/*
** $Id: lauxlib.h,v 1.131.1.1 2017/04/19 17:20:42 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
#ifndef lauxlib_h
#define lauxlib_h
#include <stddef.h>
#include <stdio.h>
#include "lua.h"
/* extra error code for 'luaL_loadfilex' */
#define LUA_ERRFILE (LUA_ERRERR+1)
/* key, in the registry, for table of loaded modules */
#define LUA_LOADED_TABLE "_LOADED"
/* key, in the registry, for table of preloaded loaders */
#define LUA_PRELOAD_TABLE "_PRELOAD"
typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;
#define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number))
LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);
#define luaL_checkversion(L) \
luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,
size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,
const char *def, size_t *l);
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,
lua_Integer def);
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int arg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,
const char *const lst[]);
LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
/* predefined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
const char *mode);
#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
const char *name, const char *mode);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
const char *r);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
const char *msg, int level);
LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
lua_CFunction openf, int glb);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define luaL_newlibtable(L,l) \
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
#define luaL_newlib(L,l) \
(luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
#define luaL_argcheck(L, cond,arg,extramsg) \
((void)((cond) || luaL_argerror(L, (arg), (extramsg))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
typedef struct luaL_Buffer {
char *b; /* buffer address */
size_t size; /* buffer size */
size_t n; /* number of characters in buffer */
lua_State *L;
char initb[LUAL_BUFFERSIZE]; /* initial buffer */
} luaL_Buffer;
#define luaL_addchar(B,c) \
((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
((B)->b[(B)->n++] = (c)))
#define luaL_addsize(B,s) ((B)->n += (s))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
/* }====================================================== */
/*
** {======================================================
** File handles for IO library
** =======================================================
*/
/*
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
** initial structure 'luaL_Stream' (it may contain other fields
** after that initial structure).
*/
#define LUA_FILEHANDLE "FILE*"
typedef struct luaL_Stream {
FILE *f; /* stream (NULL for incompletely created streams) */
lua_CFunction closef; /* to close stream (NULL for closed streams) */
} luaL_Stream;
/* }====================================================== */
/* compatibility with old module system */
#if defined(LUA_COMPAT_MODULE)
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
int sizehint);
LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
const luaL_Reg *l, int nup);
#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
#endif
/*
** {==================================================================
** "Abstraction Layer" for basic report of messages and errors
** ===================================================================
*/
/* print a string */
#if !defined(lua_writestring)
#define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
#endif
/* print a newline and flush the output */
#if !defined(lua_writeline)
#define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
#endif
/* print an error message */
#if !defined(lua_writestringerror)
#define lua_writestringerror(s,p) \
(fprintf(stderr, (s), (p)), fflush(stderr))
#endif
/* }================================================================== */
/*
** {============================================================
** Compatibility with deprecated conversions
** =============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
#define luaL_optunsigned(L,a,d) \
((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#endif
/* }============================================================ */
#endif

486
include/lua.h Normal file
View File

@@ -0,0 +1,486 @@
/*
** $Id: lua.h,v 1.332.1.2 2018/06/13 16:58:17 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
*/
#ifndef lua_h
#define lua_h
#include <stdarg.h>
#include <stddef.h>
#include "luaconf.h"
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "3"
#define LUA_VERSION_NUM 503
#define LUA_VERSION_RELEASE "5"
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2018 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
#define LUA_SIGNATURE "\x1bLua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
#define LUA_MULTRET (-1)
/*
** Pseudo-indices
** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
** space after that to help overflow detection)
*/
#define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
/* thread status */
#define LUA_OK 0
#define LUA_YIELD 1
#define LUA_ERRRUN 2
#define LUA_ERRSYNTAX 3
#define LUA_ERRMEM 4
#define LUA_ERRGCMM 5
#define LUA_ERRERR 6
typedef struct lua_State lua_State;
/*
** basic types
*/
#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
#define LUA_NUMTAGS 9
/* minimum Lua stack available to a C function */
#define LUA_MINSTACK 20
/* predefined values in the registry */
#define LUA_RIDX_MAINTHREAD 1
#define LUA_RIDX_GLOBALS 2
#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
/* type of numbers in Lua */
typedef LUA_NUMBER lua_Number;
/* type for integer functions */
typedef LUA_INTEGER lua_Integer;
/* unsigned integer type */
typedef LUA_UNSIGNED lua_Unsigned;
/* type for continuation-function contexts */
typedef LUA_KCONTEXT lua_KContext;
/*
** Type for C functions registered with Lua
*/
typedef int (*lua_CFunction) (lua_State *L);
/*
** Type for continuation functions
*/
typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
/*
** Type for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** generic extra include file
*/
#if defined(LUA_USER_H)
#include LUA_USER_H
#endif
/*
** RCS ident string
*/
extern const char lua_ident[];
/*
** state manipulation
*/
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L);
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
LUA_API const lua_Number *(lua_version) (lua_State *L);
/*
** basic stack manipulation
*/
LUA_API int (lua_absindex) (lua_State *L, int idx);
LUA_API int (lua_gettop) (lua_State *L);
LUA_API void (lua_settop) (lua_State *L, int idx);
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
LUA_API int (lua_checkstack) (lua_State *L, int n);
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
/*
** access functions (stack -> C)
*/
LUA_API int (lua_isnumber) (lua_State *L, int idx);
LUA_API int (lua_isstring) (lua_State *L, int idx);
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
LUA_API int (lua_isinteger) (lua_State *L, int idx);
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
/*
** Comparison and arithmetic functions
*/
#define LUA_OPADD 0 /* ORDER TM, ORDER OP */
#define LUA_OPSUB 1
#define LUA_OPMUL 2
#define LUA_OPMOD 3
#define LUA_OPPOW 4
#define LUA_OPDIV 5
#define LUA_OPIDIV 6
#define LUA_OPBAND 7
#define LUA_OPBOR 8
#define LUA_OPBXOR 9
#define LUA_OPSHL 10
#define LUA_OPSHR 11
#define LUA_OPUNM 12
#define LUA_OPBNOT 13
LUA_API void (lua_arith) (lua_State *L, int op);
#define LUA_OPEQ 0
#define LUA_OPLT 1
#define LUA_OPLE 2
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
/*
** push functions (C -> stack)
*/
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
/*
** get functions (Lua -> stack)
*/
LUA_API int (lua_getglobal) (lua_State *L, const char *name);
LUA_API int (lua_gettable) (lua_State *L, int idx);
LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawget) (lua_State *L, int idx);
LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
LUA_API int (lua_getuservalue) (lua_State *L, int idx);
/*
** set functions (stack -> Lua)
*/
LUA_API void (lua_setglobal) (lua_State *L, const char *name);
LUA_API void (lua_settable) (lua_State *L, int idx);
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
LUA_API void (lua_setuservalue) (lua_State *L, int idx);
/*
** 'load' and 'call' functions (load and run Lua code)
*/
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,
lua_KContext ctx, lua_KFunction k);
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
lua_KContext ctx, lua_KFunction k);
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname, const char *mode);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
/*
** coroutine functions
*/
LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx,
lua_KFunction k);
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
LUA_API int (lua_status) (lua_State *L);
LUA_API int (lua_isyieldable) (lua_State *L);
#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
/*
** garbage-collection function and options
*/
#define LUA_GCSTOP 0
#define LUA_GCRESTART 1
#define LUA_GCCOLLECT 2
#define LUA_GCCOUNT 3
#define LUA_GCCOUNTB 4
#define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7
#define LUA_GCISRUNNING 9
LUA_API int (lua_gc) (lua_State *L, int what, int data);
/*
** miscellaneous functions
*/
LUA_API int (lua_error) (lua_State *L);
LUA_API int (lua_next) (lua_State *L, int idx);
LUA_API void (lua_concat) (lua_State *L, int n);
LUA_API void (lua_len) (lua_State *L, int idx);
LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
/*
** {==============================================================
** some useful macros
** ===============================================================
*/
#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
#define lua_pushliteral(L, s) lua_pushstring(L, "" s)
#define lua_pushglobaltable(L) \
((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
/* }============================================================== */
/*
** {==============================================================
** compatibility macros for unsigned conversions
** ===============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
#define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
#endif
/* }============================================================== */
/*
** {======================================================================
** Debug API
** =======================================================================
*/
/*
** Event codes
*/
#define LUA_HOOKCALL 0
#define LUA_HOOKRET 1
#define LUA_HOOKLINE 2
#define LUA_HOOKCOUNT 3
#define LUA_HOOKTAILCALL 4
/*
** Event masks
*/
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
#define LUA_MASKRET (1 << LUA_HOOKRET)
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
typedef struct lua_Debug lua_Debug; /* activation record */
/* Functions to be called by the debugger in specific events */
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
int fidx2, int n2);
LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook (lua_gethook) (lua_State *L);
LUA_API int (lua_gethookmask) (lua_State *L);
LUA_API int (lua_gethookcount) (lua_State *L);
struct lua_Debug {
int event;
const char *name; /* (n) */
const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
const char *source; /* (S) */
int currentline; /* (l) */
int linedefined; /* (S) */
int lastlinedefined; /* (S) */
unsigned char nups; /* (u) number of upvalues */
unsigned char nparams;/* (u) number of parameters */
char isvararg; /* (u) */
char istailcall; /* (t) */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
struct CallInfo *i_ci; /* active function */
};
/* }====================================================================== */
/******************************************************************************
* Copyright (C) 1994-2018 Lua.org, PUC-Rio.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#endif

27
include/lua_core.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
bool luaInit();
int luaTraceback( lua_State *L );
bool luaCallMain();
void luaCallProcess();
void luaCallDraw();
void luaRegister();
/* Lua Util functions */
Color uluaGetColor( lua_State *L );
Vector2 uluaGetVector2( lua_State *L );
Vector3 uluaGetVector3( lua_State *L );
Rectangle uluaGetRectangle( lua_State *L );
Quaternion uluaGetQuaternion( lua_State *L );
Matrix uluaGetMatrix( lua_State *L );
BoundingBox uluaGetBoundingBox( lua_State *L );
Ray uluaGetRay( lua_State *L );
NPatchInfo uluaGetNPatchInfo( lua_State *L );
void uluaPushColor( lua_State *L, Color color );
void uluaPushVector2( lua_State *L, Vector2 vector );
void uluaPushVector3( lua_State *L, Vector3 vector );
void uluaPushRectangle( lua_State *L, Rectangle rect );
void uluaPushMatrix( lua_State *L, Matrix matrix );
void uluaPushRayCollision( lua_State *L, RayCollision rayCol );
int uluaGetTableLen( lua_State *L );

790
include/luaconf.h Normal file
View File

@@ -0,0 +1,790 @@
/*
** $Id: luaconf.h,v 1.259.1.1 2017/04/19 17:29:57 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
#ifndef luaconf_h
#define luaconf_h
#include <limits.h>
#include <stddef.h>
/*
** ===================================================================
** Search for "@@" to find all configurable definitions.
** ===================================================================
*/
/*
** {====================================================================
** System Configuration: macros to adapt (if needed) Lua to some
** particular platform, for instance compiling it with 32-bit numbers or
** restricting it to C89.
** =====================================================================
*/
/*
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You
** can also define LUA_32BITS in the make file, but changing here you
** ensure that all software connected to Lua will be compiled with the
** same configuration.
*/
/* #define LUA_32BITS */
/*
@@ LUA_USE_C89 controls the use of non-ISO-C89 features.
** Define it if you want Lua to avoid the use of a few C99 features
** or Windows-specific features on Windows.
*/
/* #define LUA_USE_C89 */
/*
** By default, Lua on Windows use (some) specific Windows features
*/
#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)
#define LUA_USE_WINDOWS /* enable goodies for regular Windows */
#endif
#if defined(LUA_USE_WINDOWS)
#define LUA_DL_DLL /* enable support for DLL */
#define LUA_USE_C89 /* broadly, Windows is C89 */
#endif
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
#define LUA_USE_READLINE /* needs some extra libraries */
#endif
#if defined(LUA_USE_MACOSX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* MacOS does not need -ldl */
#define LUA_USE_READLINE /* needs an extra library: -lreadline */
#endif
/*
@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
** C89 ('long' and 'double'); Windows always has '__int64', so it does
** not need to use this case.
*/
#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
#define LUA_C89_NUMBERS
#endif
/*
@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.
*/
/* avoid undefined shifts */
#if ((INT_MAX >> 15) >> 15) >= 1
#define LUAI_BITSINT 32
#else
/* 'int' always must have at least 16 bits */
#define LUAI_BITSINT 16
#endif
/*
@@ LUA_INT_TYPE defines the type for Lua integers.
@@ LUA_FLOAT_TYPE defines the type for Lua floats.
** Lua should work fine with any mix of these options (if supported
** by your C compiler). The usual configurations are 64-bit integers
** and 'double' (the default), 32-bit integers and 'float' (for
** restricted platforms), and 'long'/'double' (for C compilers not
** compliant with C99, which may not have support for 'long long').
*/
/* predefined options for LUA_INT_TYPE */
#define LUA_INT_INT 1
#define LUA_INT_LONG 2
#define LUA_INT_LONGLONG 3
/* predefined options for LUA_FLOAT_TYPE */
#define LUA_FLOAT_FLOAT 1
#define LUA_FLOAT_DOUBLE 2
#define LUA_FLOAT_LONGDOUBLE 3
#if defined(LUA_32BITS) /* { */
/*
** 32-bit integers and 'float'
*/
#if LUAI_BITSINT >= 32 /* use 'int' if big enough */
#define LUA_INT_TYPE LUA_INT_INT
#else /* otherwise use 'long' */
#define LUA_INT_TYPE LUA_INT_LONG
#endif
#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
#elif defined(LUA_C89_NUMBERS) /* }{ */
/*
** largest types available for C89 ('long' and 'double')
*/
#define LUA_INT_TYPE LUA_INT_LONG
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
#endif /* } */
/*
** default configuration for 64-bit Lua ('long long' and 'double')
*/
#if !defined(LUA_INT_TYPE)
#define LUA_INT_TYPE LUA_INT_LONGLONG
#endif
#if !defined(LUA_FLOAT_TYPE)
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
#endif
/* }================================================================== */
/*
** {==================================================================
** Configuration for Paths.
** ===================================================================
*/
/*
** LUA_PATH_SEP is the character that separates templates in a path.
** LUA_PATH_MARK is the string that marks the substitution points in a
** template.
** LUA_EXEC_DIR in a Windows path is replaced by the executable's
** directory.
*/
#define LUA_PATH_SEP ";"
#define LUA_PATH_MARK "?"
#define LUA_EXEC_DIR "!"
/*
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
** Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
** C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
*/
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#if defined(_WIN32) /* { */
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
#define LUA_LDIR "!\\lua\\"
#define LUA_CDIR "!\\"
#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
".\\?.lua;" ".\\?\\init.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.dll;" \
LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
LUA_CDIR"loadall.dll;" ".\\?.dll"
#else /* }{ */
#define LUA_ROOT "/usr/local/"
#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/"
#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/"
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
"./?.lua;" "./?/init.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
#endif /* } */
/*
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
*/
#if defined(_WIN32)
#define LUA_DIRSEP "\\"
#else
#define LUA_DIRSEP "/"
#endif
/* }================================================================== */
/*
** {==================================================================
** Marks for exported symbols in the C code
** ===================================================================
*/
/*
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all auxiliary library functions.
@@ LUAMOD_API is a mark for all standard library opening functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
#if defined(LUA_BUILD_AS_DLL) /* { */
#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
#define LUA_API __declspec(dllexport)
#else /* }{ */
#define LUA_API __declspec(dllimport)
#endif /* } */
#else /* }{ */
#define LUA_API extern
#endif /* } */
/* more often than not the libs go together with the core */
#define LUALIB_API LUA_API
#define LUAMOD_API LUALIB_API
/*
@@ LUAI_FUNC is a mark for all extern functions that are not to be
** exported to outside modules.
@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
** that are not to be exported to outside modules (LUAI_DDEF for
** definitions and LUAI_DDEC for declarations).
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library. Not all elf targets support
** this attribute. Unfortunately, gcc does not offer a way to check
** whether the target offers that support, and those without support
** give a warning about it. To avoid these warnings, change to the
** default definition.
*/
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__) /* { */
#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
#else /* }{ */
#define LUAI_FUNC extern
#endif /* } */
#define LUAI_DDEC LUAI_FUNC
#define LUAI_DDEF /* empty */
/* }================================================================== */
/*
** {==================================================================
** Compatibility with previous versions
** ===================================================================
*/
/*
@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2.
@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.
** You can define it to get all options, or change specific options
** to fit your specific needs.
*/
#if defined(LUA_COMPAT_5_2) /* { */
/*
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
** functions in the mathematical library.
*/
#define LUA_COMPAT_MATHLIB
/*
@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.
*/
#define LUA_COMPAT_BITLIB
/*
@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.
*/
#define LUA_COMPAT_IPAIRS
/*
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
** luaL_checkint, luaL_checklong, etc.)
*/
#define LUA_COMPAT_APIINTCASTS
#endif /* } */
#if defined(LUA_COMPAT_5_1) /* { */
/* Incompatibilities from 5.2 -> 5.3 */
#define LUA_COMPAT_MATHLIB
#define LUA_COMPAT_APIINTCASTS
/*
@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
** You can replace it with 'table.unpack'.
*/
#define LUA_COMPAT_UNPACK
/*
@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
** You can replace it with 'package.searchers'.
*/
#define LUA_COMPAT_LOADERS
/*
@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
** You can call your C function directly (with light C functions).
*/
#define lua_cpcall(L,f,u) \
(lua_pushcfunction(L, (f)), \
lua_pushlightuserdata(L,(u)), \
lua_pcall(L,1,0,0))
/*
@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
** You can rewrite 'log10(x)' as 'log(x, 10)'.
*/
#define LUA_COMPAT_LOG10
/*
@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
** library. You can rewrite 'loadstring(s)' as 'load(s)'.
*/
#define LUA_COMPAT_LOADSTRING
/*
@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
*/
#define LUA_COMPAT_MAXN
/*
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
*/
#define lua_strlen(L,i) lua_rawlen(L, (i))
#define lua_objlen(L,i) lua_rawlen(L, (i))
#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
/*
@@ LUA_COMPAT_MODULE controls compatibility with previous
** module functions 'module' (Lua) and 'luaL_register' (C).
*/
#define LUA_COMPAT_MODULE
#endif /* } */
/*
@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a
@@ a float mark ('.0').
** This macro is not on by default even in compatibility mode,
** because this is not really an incompatibility.
*/
/* #define LUA_COMPAT_FLOATSTRING */
/* }================================================================== */
/*
** {==================================================================
** Configuration for Numbers.
** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
** satisfy your needs.
** ===================================================================
*/
/*
@@ LUA_NUMBER is the floating-point type used by Lua.
@@ LUAI_UACNUMBER is the result of a 'default argument promotion'
@@ over a floating number.
@@ l_mathlim(x) corrects limit name 'x' to the proper float type
** by prefixing it with one of FLT/DBL/LDBL.
@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
@@ LUA_NUMBER_FMT is the format for writing floats.
@@ lua_number2str converts a float to a string.
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
@@ l_floor takes the floor of a float.
@@ lua_str2number converts a decimal numeric string to a number.
*/
/* The following definitions are good for most cases here */
#define l_floor(x) (l_mathop(floor)(x))
#define lua_number2str(s,sz,n) \
l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))
/*
@@ lua_numbertointeger converts a float number to an integer, or
** returns 0 if float is not within the range of a lua_Integer.
** (The range comparisons are tricky because of rounding. The tests
** here assume a two-complement representation, where MININTEGER always
** has an exact representation as a float; MAXINTEGER may not have one,
** and therefore its conversion to float may have an ill-defined value.)
*/
#define lua_numbertointeger(n,p) \
((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
(n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
(*(p) = (LUA_INTEGER)(n), 1))
/* now the variable definitions */
#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
#define LUA_NUMBER float
#define l_mathlim(n) (FLT_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.7g"
#define l_mathop(op) op##f
#define lua_str2number(s,p) strtof((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */
#define LUA_NUMBER long double
#define l_mathlim(n) (LDBL_##n)
#define LUAI_UACNUMBER long double
#define LUA_NUMBER_FRMLEN "L"
#define LUA_NUMBER_FMT "%.19Lg"
#define l_mathop(op) op##l
#define lua_str2number(s,p) strtold((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */
#define LUA_NUMBER double
#define l_mathlim(n) (DBL_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.14g"
#define l_mathop(op) op
#define lua_str2number(s,p) strtod((s), (p))
#else /* }{ */
#error "numeric float type not defined"
#endif /* } */
/*
@@ LUA_INTEGER is the integer type used by Lua.
**
@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
**
@@ LUAI_UACINT is the result of a 'default argument promotion'
@@ over a lUA_INTEGER.
@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
@@ LUA_INTEGER_FMT is the format for writing integers.
@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
@@ lua_integer2str converts an integer to a string.
*/
/* The following definitions are good for most cases here */
#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
#define LUAI_UACINT LUA_INTEGER
#define lua_integer2str(s,sz,n) \
l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))
/*
** use LUAI_UACINT here to avoid problems with promotions (which
** can turn a comparison between unsigneds into a signed comparison)
*/
#define LUA_UNSIGNED unsigned LUAI_UACINT
/* now the variable definitions */
#if LUA_INT_TYPE == LUA_INT_INT /* { int */
#define LUA_INTEGER int
#define LUA_INTEGER_FRMLEN ""
#define LUA_MAXINTEGER INT_MAX
#define LUA_MININTEGER INT_MIN
#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */
#define LUA_INTEGER long
#define LUA_INTEGER_FRMLEN "l"
#define LUA_MAXINTEGER LONG_MAX
#define LUA_MININTEGER LONG_MIN
#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */
/* use presence of macro LLONG_MAX as proxy for C99 compliance */
#if defined(LLONG_MAX) /* { */
/* use ISO C99 stuff */
#define LUA_INTEGER long long
#define LUA_INTEGER_FRMLEN "ll"
#define LUA_MAXINTEGER LLONG_MAX
#define LUA_MININTEGER LLONG_MIN
#elif defined(LUA_USE_WINDOWS) /* }{ */
/* in Windows, can use specific Windows types */
#define LUA_INTEGER __int64
#define LUA_INTEGER_FRMLEN "I64"
#define LUA_MAXINTEGER _I64_MAX
#define LUA_MININTEGER _I64_MIN
#else /* }{ */
#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \
or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
#endif /* } */
#else /* }{ */
#error "numeric integer type not defined"
#endif /* } */
/* }================================================================== */
/*
** {==================================================================
** Dependencies with C99 and other C details
** ===================================================================
*/
/*
@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
** (All uses in Lua have only one format item.)
*/
#if !defined(LUA_USE_C89)
#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)
#else
#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))
#endif
/*
@@ lua_strx2number converts an hexadecimal numeric string to a number.
** In C99, 'strtod' does that conversion. Otherwise, you can
** leave 'lua_strx2number' undefined and Lua will provide its own
** implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_strx2number(s,p) lua_str2number(s,p)
#endif
/*
@@ lua_pointer2str converts a pointer to a readable string in a
** non-specified way.
*/
#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)
/*
@@ lua_number2strx converts a float to an hexadecimal numeric string.
** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
** provide its own implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_number2strx(L,b,sz,f,n) \
((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
#endif
/*
** 'strtof' and 'opf' variants for math functions are not valid in
** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the
** availability of these variants. ('math.h' is already included in
** all files that use these macros.)
*/
#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))
#undef l_mathop /* variants not available */
#undef lua_str2number
#define l_mathop(op) (lua_Number)op /* no variant */
#define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
#endif
/*
@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation
** functions. It must be a numerical type; Lua will use 'intptr_t' if
** available, otherwise it will use 'ptrdiff_t' (the nearest thing to
** 'intptr_t' in C89)
*/
#define LUA_KCONTEXT ptrdiff_t
#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
__STDC_VERSION__ >= 199901L
#include <stdint.h>
#if defined(INTPTR_MAX) /* even in C99 this type is optional */
#undef LUA_KCONTEXT
#define LUA_KCONTEXT intptr_t
#endif
#endif
/*
@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
** Change that if you do not want to use C locales. (Code using this
** macro must include header 'locale.h'.)
*/
#if !defined(lua_getlocaledecpoint)
#define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
#endif
/* }================================================================== */
/*
** {==================================================================
** Language Variations
** =====================================================================
*/
/*
@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some
** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from
** numbers to strings. Define LUA_NOCVTS2N to turn off automatic
** coercion from strings to numbers.
*/
/* #define LUA_NOCVTN2S */
/* #define LUA_NOCVTS2N */
/*
@@ LUA_USE_APICHECK turns on several consistency checks on the C API.
** Define it as a help when debugging C code.
*/
#if defined(LUA_USE_APICHECK)
#include <assert.h>
#define luai_apicheck(l,e) assert(e)
#endif
/* }================================================================== */
/*
** {==================================================================
** Macros that affect the API and must be stable (that is, must be the
** same when you compile Lua and when you compile code that links to
** Lua). You probably do not want/need to change them.
** =====================================================================
*/
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
*/
#if LUAI_BITSINT >= 32
#define LUAI_MAXSTACK 1000000
#else
#define LUAI_MAXSTACK 15000
#endif
/*
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
*/
#define LUA_EXTRASPACE (sizeof(void *))
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ of a function in debug information.
** CHANGE it if you want a different size.
*/
#define LUA_IDSIZE 60
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
** CHANGE it if it uses too much C-stack space. (For long double,
** 'string.format("%.99f", -1e4932)' needs 5034 bytes, so a
** smaller buffer would force a memory allocation for each call to
** 'string.format'.)
*/
#if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE
#define LUAL_BUFFERSIZE 8192
#else
#define LUAL_BUFFERSIZE ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))
#endif
/* }================================================================== */
/*
@@ LUA_QL describes how error messages quote program elements.
** Lua does not use these macros anymore; they are here for
** compatibility only.
*/
#define LUA_QL(x) "'" x "'"
#define LUA_QS LUA_QL("%s")
/* =================================================================== */
/*
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
*/
#endif

61
include/lualib.h Normal file
View File

@@ -0,0 +1,61 @@
/*
** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
#ifndef lualib_h
#define lualib_h
#include "lua.h"
/* version suffix for environment variable names */
#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
LUAMOD_API int (luaopen_base) (lua_State *L);
#define LUA_COLIBNAME "coroutine"
LUAMOD_API int (luaopen_coroutine) (lua_State *L);
#define LUA_TABLIBNAME "table"
LUAMOD_API int (luaopen_table) (lua_State *L);
#define LUA_IOLIBNAME "io"
LUAMOD_API int (luaopen_io) (lua_State *L);
#define LUA_OSLIBNAME "os"
LUAMOD_API int (luaopen_os) (lua_State *L);
#define LUA_STRLIBNAME "string"
LUAMOD_API int (luaopen_string) (lua_State *L);
#define LUA_UTF8LIBNAME "utf8"
LUAMOD_API int (luaopen_utf8) (lua_State *L);
#define LUA_BITLIBNAME "bit32"
LUAMOD_API int (luaopen_bit32) (lua_State *L);
#define LUA_MATHLIBNAME "math"
LUAMOD_API int (luaopen_math) (lua_State *L);
#define LUA_DBLIBNAME "debug"
LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
#if !defined(lua_assert)
#define lua_assert(x) ((void)0)
#endif
#endif

16
include/main.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#define STRING_LEN 1024
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "raylib.h"
#include "raymath.h"
#include "rlgl.h"
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

68
include/models.h Normal file
View File

@@ -0,0 +1,68 @@
#pragma once
/* Basic. */
int lmodelsDrawLine3D( lua_State *L );
int lmodelsDrawPoint3D( lua_State *L );
int lmodelsDrawCircle3D( lua_State *L );
int lmodelsDrawTriangle3D( lua_State *L );
int lmodelsDrawCube( lua_State *L );
int lmodelsDrawCubeWires( lua_State *L );
int lmodelsDrawCubeTexture( lua_State *L );
int lmodelsDrawSphere( lua_State *L );
int lmodelsDrawSphereEx( lua_State *L );
int lmodelsDrawSphereWires( lua_State *L );
int lmodelsDrawCylinder( lua_State *L );
int lmodelsDrawCylinderEx( lua_State *L );
int lmodelsDrawCylinderWires( lua_State *L );
int lmodelsDrawCylinderWiresEx( lua_State *L );
int lmodelsDrawPlane( lua_State *L );
int lmodelDrawQuad3DTexture( lua_State *L );
int lmodelsDrawRay( lua_State *L );
int lmodelsDrawGrid( lua_State *L );
/* Mesh. */
int lmodelsGenMeshPoly( lua_State *L );
int lmodelsGenMeshPlane( lua_State *L );
int lmodelsGenMeshCube( lua_State *L );
int lmodelsGenMeshSphere( lua_State *L );
int lmodelsGenMeshCylinder( lua_State *L );
int lmodelsGenMeshCone( lua_State *L );
int lmodelsGenMeshTorus( lua_State *L );
int lmodelsGenMeshKnot( lua_State *L );
int lmodelsGenMeshHeightmap( lua_State *L );
int lmodelsGenMeshCustom( lua_State *L );
int lmodelsUnloadMesh( lua_State *L );
int lmodelsDrawMesh( lua_State *L );
int lmodelsDrawMeshInstanced( lua_State *L );
int lmodelsSetMeshColor( lua_State *L );
/* Material. */
int lmodelsLoadMaterialDefault( lua_State *L );
int lmodelsCreateMaterial( lua_State *L );
int lmodelsUnloadMaterial( lua_State *L );
int lmodelsSetMaterialTexture( lua_State *L );
int lmodelsSetMaterialColor( lua_State *L );
int lmodelsSetMaterialValue( lua_State *L );
/* Model. */
int lmodelsLoadModel( lua_State *L );
int lmodelsLoadModelFromMesh( lua_State *L );
int lmodelsUnloadModel( lua_State *L );
int lmodelsDrawModel( lua_State *L );
int lmodelsDrawModelEx( lua_State *L );
int lmodelsSetModelMaterial( lua_State *L );
int lmodelsSetModelMeshMaterial( lua_State *L );
int lmodelsDrawBillboard( lua_State *L );
int lmodelsDrawBillboardRec( lua_State *L );
/* Animations. */
int lmodelsLoadModelAnimations( lua_State *L );
int lmodelsUpdateModelAnimation( lua_State *L );
int lmodelsGetModelAnimationBoneCount( lua_State *L );
int lmodelsGetModelAnimationFrameCount( lua_State *L );
/* Collision. */
int lmodelsCheckCollisionSpheres( lua_State *L );
int lmodelsCheckCollisionBoxes( lua_State *L );
int lmodelsCheckCollisionBoxSphere( lua_State *L );
int lmodelsGetRayCollisionSphere( lua_State *L );
int lmodelsGetRayCollisionBox( lua_State *L );
int lmodelsGetRayCollisionModel( lua_State *L );
int lmodelsGetRayCollisionMesh( lua_State *L );
int lmodelsGetRayCollisionTriangle( lua_State *L );
int lmodelsGetRayCollisionQuad( lua_State *L );

198
include/raudio.h Normal file
View File

@@ -0,0 +1,198 @@
/**********************************************************************************************
*
* raudio v1.0 - A simple and easy-to-use audio library based on miniaudio
*
* FEATURES:
* - Manage audio device (init/close)
* - Load and unload audio files
* - Format wave data (sample rate, size, channels)
* - Play/Stop/Pause/Resume loaded audio
* - Manage mixing channels
* - Manage raw audio context
*
* DEPENDENCIES:
* miniaudio.h - Audio device management lib (https://github.com/dr-soft/miniaudio)
* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
* dr_mp3.h - MP3 audio file loading (https://github.com/mackron/dr_libs)
* dr_flac.h - FLAC audio file loading (https://github.com/mackron/dr_libs)
* jar_xm.h - XM module file loading
* jar_mod.h - MOD audio file loading
*
* CONTRIBUTORS:
* David Reid (github: @mackron) (Nov. 2017):
* - Complete port to miniaudio library
*
* Joshua Reisenauer (github: @kd7tck) (2015)
* - XM audio module support (jar_xm)
* - MOD audio module support (jar_mod)
* - Mixing channels support
* - Raw audio context support
*
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2014-2021 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you
* wrote the original software. If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
**********************************************************************************************/
#ifndef RAUDIO_H
#define RAUDIO_H
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
// Allow custom memory allocators
#ifndef RL_MALLOC
#define RL_MALLOC(sz) malloc(sz)
#endif
#ifndef RL_CALLOC
#define RL_CALLOC(n,sz) calloc(n,sz)
#endif
#ifndef RL_FREE
#define RL_FREE(p) free(p)
#endif
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
#ifndef __cplusplus
// Boolean type
#if !defined(_STDBOOL_H)
typedef enum { false, true } bool;
#define _STDBOOL_H
#endif
#endif
// Wave, audio wave data
typedef struct Wave {
unsigned int frameCount; // Total number of frames (considering channels)
unsigned int sampleRate; // Frequency (samples per second)
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
unsigned int channels; // Number of channels (1-mono, 2-stereo, ...)
void *data; // Buffer data pointer
} Wave;
typedef struct rAudioBuffer rAudioBuffer;
// AudioStream, custom audio stream
typedef struct AudioStream {
rAudioBuffer *buffer; // Pointer to internal data used by the audio system
unsigned int sampleRate; // Frequency (samples per second)
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
unsigned int channels; // Number of channels (1-mono, 2-stereo, ...)
} AudioStream;
// Sound
typedef struct Sound {
AudioStream stream; // Audio stream
unsigned int frameCount; // Total number of frames (considering channels)
} Sound;
// Music, audio stream, anything longer than ~10 seconds should be streamed
typedef struct Music {
AudioStream stream; // Audio stream
unsigned int frameCount; // Total number of frames (considering channels)
bool looping; // Music looping enable
int ctxType; // Type of music context (audio filetype)
void *ctxData; // Audio context data, depends on type
} Music;
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
//...
//----------------------------------------------------------------------------------
// Module Functions Declaration
//----------------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" { // Prevents name mangling of functions
#endif
// Audio device management functions
void InitAudioDevice(void); // Initialize audio device and context
void CloseAudioDevice(void); // Close the audio device and context
bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully
void SetMasterVolume(float volume); // Set master volume (listener)
// Wave/Sound loading/unloading functions
Wave LoadWave(const char *fileName); // Load wave data from file
Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int dataSize); // Load wave from memory buffer, fileType refers to extension: i.e. ".wav"
Sound LoadSound(const char *fileName); // Load sound from file
Sound LoadSoundFromWave(Wave wave); // Load sound from wave data
void UpdateSound(Sound sound, const void *data, int samplesCount);// Update sound buffer with new data
void UnloadWave(Wave wave); // Unload wave data
void UnloadSound(Sound sound); // Unload sound
bool ExportWave(Wave wave, const char *fileName); // Export wave data to file, returns true on success
bool ExportWaveAsCode(Wave wave, const char *fileName); // Export wave sample data to code (.h), returns true on success
// Wave/Sound management functions
void PlaySound(Sound sound); // Play a sound
void StopSound(Sound sound); // Stop playing a sound
void PauseSound(Sound sound); // Pause a sound
void ResumeSound(Sound sound); // Resume a paused sound
void PlaySoundMulti(Sound sound); // Play a sound (using multichannel buffer pool)
void StopSoundMulti(void); // Stop any sound playing (using multichannel buffer pool)
int GetSoundsPlaying(void); // Get number of sounds playing in the multichannel
bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing
void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format
Wave WaveCopy(Wave wave); // Copy a wave to a new wave
void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range
float *LoadWaveSamples(Wave wave); // Load samples data from wave as a floats array
void UnloadWaveSamples(float *samples); // Unload samples data loaded with LoadWaveSamples()
// Music management functions
Music LoadMusicStream(const char *fileName); // Load music stream from file
Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int dataSize); // Load music stream from data
void UnloadMusicStream(Music music); // Unload music stream
void PlayMusicStream(Music music); // Start music playing
bool IsMusicStreamPlaying(Music music); // Check if music is playing
void UpdateMusicStream(Music music); // Updates buffers for music streaming
void StopMusicStream(Music music); // Stop music playing
void PauseMusicStream(Music music); // Pause music playing
void ResumeMusicStream(Music music); // Resume playing paused music
void SeekMusicStream(Music music, float position); // Seek music to a position (in seconds)
void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level)
void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level)
float GetMusicTimeLength(Music music); // Get music time length (in seconds)
float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
// AudioStream management functions
AudioStream LoadAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels); // Load audio stream (to stream raw audio pcm data)
void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount); // Update audio stream buffers with data
void UnloadAudioStream(AudioStream stream); // Unload audio stream and free memory
bool IsAudioStreamProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
void PlayAudioStream(AudioStream stream); // Play audio stream
void PauseAudioStream(AudioStream stream); // Pause audio stream
void ResumeAudioStream(AudioStream stream); // Resume audio stream
bool IsAudioStreamPlaying(AudioStream stream); // Check if audio stream is playing
void StopAudioStream(AudioStream stream); // Stop audio stream
void SetAudioStreamVolume(AudioStream stream, float volume); // Set volume for audio stream (1.0 is max level)
void SetAudioStreamPitch(AudioStream stream, float pitch); // Set pitch for audio stream (1.0 is base level)
void SetAudioStreamBufferSizeDefault(int size); // Default size for new audio streams
#ifdef __cplusplus
}
#endif
#endif // RAUDIO_H

4342
include/raygui.h Normal file

File diff suppressed because it is too large Load Diff

1538
include/raylib.h Normal file

File diff suppressed because it is too large Load Diff

1850
include/raymath.h Normal file

File diff suppressed because it is too large Load Diff

27
include/rgui.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
/* Global. */
int lguiGuiEnable( lua_State *L );
int lguiGuiDisable( lua_State *L );
int lguiGuiLock( lua_State *L );
int lguiGuiUnlock( lua_State *L );
/* Font. */
int lguiGuiSetFont( lua_State *L );
/* Container. */
int lguiGuiWindowBox( lua_State *L );
int lguiGuiPanel( lua_State *L );
int lguiGuiScrollPanel( lua_State *L );
/* Basic. */
int lguiGuiLabel( lua_State *L );
int lguiGuiButton( lua_State *L );
int lguiGuiToggle( lua_State *L );
int lguiGuiCheckBox( lua_State *L );
int lguiGuiTextBox( lua_State *L );
int lguiGuiTextBoxMulti( lua_State *L );
int lguiGuiSpinner( lua_State *L );
int lguiGuiValueBox( lua_State *L );
int lguiGuiSlider( lua_State *L );
int lguiGuiSliderBar( lua_State *L );
int lguiGuiProgressBar( lua_State *L );
int lguiGuiScrollBar( lua_State *L );
int lguiGuiDropdownBox( lua_State *L );

4673
include/rlgl.h Normal file

File diff suppressed because it is too large Load Diff

50
include/rmath.h Normal file
View File

@@ -0,0 +1,50 @@
#pragma once
int imin( int a, int b );
int imax( int a, int b );
/* Vector2. */
int lmathVector2Add( lua_State *L );
int lmathVector2Subtract( lua_State *L );
int lmathVector2Multiply( lua_State *L );
int lmathVector2Length( lua_State *L );
int lmathVector2DotProduct( lua_State *L );
int lmathVector2Distance( lua_State *L );
int lmathVector2Angle( lua_State *L );
int lmathVector2Normalize( lua_State *L );
int lmathVector2Lerp( lua_State *L );
int lmathVector2Reflect( lua_State *L );
int lmathVector2Rotate( lua_State *L );
int lmathVector2MoveTowards( lua_State *L );
/* Vector3. */
int lmathVector3Add( lua_State *L );
int lmathVector3Subtract( lua_State *L );
int lmathVector3Multiply( lua_State *L );
int lmathVector3CrossProduct( lua_State *L );
int lmathVector3Perpendicular( lua_State *L );
int lmathVector3Length( lua_State *L );
int lmathVector3LengthSqr( lua_State *L );
int lmathVector3DotProduct( lua_State *L );
int lmathVector3Distance( lua_State *L );
int lmathVector3Normalize( lua_State *L );
int lmathVector3OrthoNormalize( lua_State *L );
int lmathVector3Transform( lua_State *L );
int lmathVector3RotateByQuaternion( lua_State *L );
int lmathVector3Lerp( lua_State *L );
int lmathVector3Reflect( lua_State *L );
/* Matrix. */
int lmathMatrixDeterminant( lua_State *L );
int lmathMatrixTranspose( lua_State *L );
int lmathMatrixInvert( lua_State *L );
int lmathMatrixNormalize( lua_State *L );
int lmathMatrixIdentity( lua_State *L );
int lmathMatrixAdd( lua_State *L );
int lmathMatrixSubtract( lua_State *L );
int lmathMatrixMultiply( lua_State *L );
int lmathMatrixTranslate( lua_State *L );
int lmathMatrixRotate( lua_State *L );
int lmathMatrixScale( lua_State *L );
int lmathMatrixFrustum( lua_State *L );
int lmathMatrixPerspective( lua_State *L );
int lmathMatrixOrtho( lua_State *L );
int lmathMatrixLookAt( lua_State *L );

21
include/shapes.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
/* Drawing. */
int lshapesDrawPixel( lua_State *L );
int lshapesDrawLine( lua_State *L );
int lshapesDrawCircle( lua_State *L );
int lshapesDrawCircleLines( lua_State *L );
int lshapesDrawRectangle( lua_State *L );
int lshapesDrawRectanglePro( lua_State *L );
int lshapesDrawTriangle( lua_State *L );
int lshapesDrawTriangleLines( lua_State *L );
/* Collision. */
int lshapesCheckCollisionRecs( lua_State *L );
int lshapesCheckCollisionCircles( lua_State *L );
int lshapesCheckCollisionCircleRec( lua_State *L );
int lshapesCheckCollisionPointRec( lua_State *L );
int lshapesCheckCollisionPointCircle( lua_State *L );
int lshapesCheckCollisionPointTriangle( lua_State *L );
int lshapesCheckCollisionLines( lua_State *L );
int lshapesCheckCollisionPointLine( lua_State *L );
int lshapesGetCollisionRec( lua_State *L );

71
include/state.h Normal file
View File

@@ -0,0 +1,71 @@
#pragma once
#define ALLOC_PAGE_SIZE 256
typedef struct {
ModelAnimation *animations;
unsigned int animCount;
} ModelAnimations;
typedef struct {
char *exePath;
bool hasWindow;
bool run;
lua_State *luaState;
Vector2 resolution;
int targetFPS;
int textureSource;
/* Resources. */
/* Images. */
Image **images;
size_t imageCount;
size_t imageAlloc;
/* Textures. */
Texture **textures;
size_t textureCount;
size_t textureAlloc;
/* RenderTextures. */
RenderTexture **renderTextures;
size_t renderTextureCount;
size_t renderTextureAlloc;
/* Fonts. */
Font **fonts;
size_t fontCount;
size_t fontAlloc;
/* Sounds. */
Sound **sounds;
size_t soundCount;
size_t soundAlloc;
/* Music. */
Music music;
/* Camera3D's. */
Camera3D **camera3Ds;
size_t camera3DCount;
size_t camera3DAlloc;
/* Meshes. */
Mesh **meshes;
size_t meshCount;
size_t meshAlloc;
/* Materials. */
Material **materials;
size_t materialCount;
size_t materialAlloc;
/* Models. */
Model **models;
size_t modelCount;
size_t modelAlloc;
/* ModelAnimations. */
ModelAnimations **animations;
size_t animationCount;
size_t animationAlloc;
/* Shaders. */
Shader **shaders;
size_t shaderCount;
size_t shaderAlloc;
} State;
extern State *state;
bool stateInit( const char *exePath );
// bool stateRun();
void stateFree();

8
include/text.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
/* Validators. */
bool validFont( size_t id );
/* Loading. */
int lmodelsLoadFont( lua_State *L );
/* Drawing. */
int ltextDrawText( lua_State *L );

44
include/textures.h Normal file
View File

@@ -0,0 +1,44 @@
#pragma once
enum TEXTURE_SOURCES { TEXTURE_SOURCE_TEXTURE, TEXTURE_SOURCE_RENDER_TEXTURE };
/* Validators. */
bool validImage( size_t id );
bool validTexture( size_t id );
bool validRenderTexture( size_t id );
bool validSourceTexture( size_t id );
Texture2D* texturesGetSourceTexture( size_t index );
/* File. */
int ltexturesLoadImage( lua_State *L );
int ltexturesGenImageColor( lua_State *L );
int ltexturesUnloadImage( lua_State *L );
int ltexturesLoadTexture( lua_State *L );
int ltexturesLoadTextureFromImage( lua_State *L );
int ltexturesUnloadTexture( lua_State *L );
int ltexturesLoadRenderTexture( lua_State *L );
int ltexturesUnloadRenderTexture( lua_State *L );
/* Image Drawing. */
int ltexturesImageClearBackground( lua_State *L );
int ltexturesImageDrawPixel( lua_State *L );
int ltexturesImageDrawLine( lua_State *L );
int ltexturesImageDrawCircle( lua_State *L );
int ltexturesImageDrawRectangle( lua_State *L );
int ltexturesImageDrawRectangleLines( lua_State *L );
int ltexturesImageDraw( lua_State *L );
int ltexturesImageDrawTextEx( lua_State *L );
/* Texture Drawing. */
int ltexturesDrawTexture( lua_State *L );
int ltexturesDrawTextureRec( lua_State *L );
int ltexturesDrawTextureTiled( lua_State *L );
int ltexturesDrawTexturePro( lua_State *L );
int ltexturesDrawTextureNPatch( lua_State *L );
int ltexturesDrawTexturePoly( lua_State *L );
int ltexturesBeginTextureMode( lua_State *L );
int ltexturesEndTextureMode( lua_State *L );
int ltexturesSetTextureSource( lua_State *L );
int ltexturesGetTextureSource( lua_State *L );
/* Conf. */
int ltexturesGenTextureMipmaps( lua_State *L );
int ltexturesSetTextureFilter( lua_State *L );
int ltexturesSetTextureWrap( lua_State *L );
int ltexturesGetTextureSize( lua_State *L );

272
src/audio.c Normal file
View File

@@ -0,0 +1,272 @@
#include "main.h"
#include "state.h"
#include "audio.h"
#include "lua_core.h"
static bool validSound( size_t id ) {
if ( id < 0 || state->soundCount < id || state->sounds[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid sound", id );
return false;
}
else {
return true;
}
}
static void checkSoundRealloc( int i ) {
if ( i == state->soundCount ) {
state->soundCount++;
}
if ( state->soundCount == state->soundAlloc ) {
state->soundAlloc += ALLOC_PAGE_SIZE;
state->sounds = realloc( state->sounds, state->soundAlloc * sizeof( Sound* ) );
for ( i = state->soundCount; i < state->soundAlloc; i++ ) {
state->sounds[i] = NULL;
}
}
}
/*
## Audio - Sounds
*/
/*
> sound = RL_LoadSound( string fileName )
Load sound from file
- Failure return -1
- Success return int
*/
int laudioLoadSound( lua_State *L ) {
if ( !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadSound( string fileName )" );
lua_pushinteger( L, -1 );
return 1;
}
if ( FileExists( lua_tostring( L, -1 ) ) ) {
int i = 0;
for ( i = 0; i < state->soundCount; i++ ) {
if ( state->sounds[i] == NULL ) {
break;
}
}
state->sounds[i] = malloc( sizeof( Sound ) );
*state->sounds[i] = LoadSound( lua_tostring( L, -1 ) );
lua_pushinteger( L, i );
checkSoundRealloc( i );
}
return 1;
}
/*
> success = RL_PlaySoundMulti( Sound sound )
Play a sound ( Using multichannel buffer pool )
- Failure return false
- Success return true
*/
int laudioPlaySoundMulti( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_PlaySoundMulti( Sound sound )" );
lua_pushboolean( L, false );
return 1;
}
if ( !validSound( lua_tointeger( L, -1 ) ) ) {
lua_pushboolean( L, false );
return 1;
}
PlaySoundMulti( *state->sounds[ lua_tointeger( L, -1 ) ] );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_SetSoundVolume( Sound sound, float volume )
Set volume for a sound ( 1.0 is max level )
- Failure return false
- Success return true
*/
int laudioSetSoundVolume( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetSoundVolume( Sound sound, float volume )" );
lua_pushboolean( L, false );
return 1;
}
if ( !validSound( lua_tointeger( L, -2 ) ) ) {
lua_pushboolean( L, false );
return 1;
}
SetSoundVolume( *state->sounds[ lua_tointeger( L, -2 ) ], lua_tonumber( L, -1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_SetSoundPitch( Sound sound, float pitch )
Set pitch for a sound ( 1.0 is base level )
- Failure return false
- Success return true
*/
int laudioSetSoundPitch( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetSoundPitch( Sound sound, float pitch )" );
lua_pushboolean( L, false );
return 1;
}
if ( !validSound( lua_tointeger( L, -2 ) ) ) {
lua_pushboolean( L, false );
return 1;
}
SetSoundPitch( *state->sounds[ lua_tointeger( L, -2 ) ], lua_tonumber( L, -1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_UnloadSound( Sound sound )
Unload sound
- Failure return false
- Success return true
*/
int laudioUnloadSound( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadSound( Sound sound )" );
lua_pushboolean( L, false );
return 1;
}
size_t id = lua_tointeger( L, -1 );
if ( !validSound( id ) ) {
lua_pushboolean( L, false );
return 1;
}
UnloadSound( *state->sounds[ id ] );
state->sounds[ id ] = NULL;
lua_pushboolean( L, true );
return 1;
}
/*
## Audio - Music
*/
/*
> success = RL_LoadMusicStream( string fileName )
Load music stream from file
- Failure return false
- Success return true
*/
int laudioLoadMusicStream( lua_State *L ) {
if ( !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadMusicStream( string fileName )" );
lua_pushboolean( L, false );
return 1;
}
if ( FileExists( lua_tostring( L, -1 ) ) ) {
state->music = LoadMusicStream( lua_tostring( L, -1 ) );
state->music.looping = false;
lua_pushboolean( L, true );
}
else {
lua_pushboolean( L, false );
}
return 1;
}
/*
> PlayMusicStream()
Start music playing
*/
int laudioPlayMusicStream( lua_State *L ) {
PlayMusicStream( state->music );
return 1;
}
/*
> StopMusicStream()
Stop music playing
*/
int laudioStopMusicStream( lua_State *L ) {
StopMusicStream( state->music );
return 1;
}
/*
> PauseMusicStream()
Pause music playing
*/
int laudioPauseMusicStream( lua_State *L ) {
PauseMusicStream( state->music );
return 1;
}
/*
> ResumeMusicStream()
Resume playing paused music
*/
int laudioResumeMusicStream( lua_State *L ) {
ResumeMusicStream( state->music );
return 1;
}
/*
> playing = PlayMusicStream()
Check if music is playing
- Success return bool
*/
int laudioIsMusicStreamPlaying( lua_State *L ) {
lua_pushboolean( L, IsMusicStreamPlaying( state->music ) );
return 1;
}
/*
> success = RL_SetMusicVolume( float volume )
Set volume for music ( 1.0 is max level )
- Failure return false
- Success return true
*/
int laudioSetMusicVolume( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetMusicVolume( float volume )" );
lua_pushboolean( L, false );
return 1;
}
SetMusicVolume( state->music, lua_tonumber( L, -1 ) );
lua_pushboolean( L, true );
return 1;
}

1908
src/core.c Normal file

File diff suppressed because it is too large Load Diff

1033
src/lua_core.c Normal file

File diff suppressed because it is too large Load Diff

37
src/main.c Normal file
View File

@@ -0,0 +1,37 @@
#include "main.h"
#include "state.h"
#include "lua_core.h"
int main( int argn, const char **argc ) {
char exePath[ STRING_LEN ] = { '\0' };
if ( 1 < argn ) {
if ( strcmp( argc[1], "--version" ) == 0 || strcmp( argc[1], "-v" ) == 0 ) {
printf( "ReiLua %d.%d\n", VERSION_MAJOR, VERSION_MINOR );
return 1;
}
else{
sprintf( exePath, "%s/%s", GetWorkingDirectory(), argc[1] );
}
}
else {
sprintf( exePath, "%s/", GetWorkingDirectory() );
}
stateInit( exePath );
while ( state->run ) {
if ( WindowShouldClose() ) {
state->run = false;
}
if ( IsAudioDeviceReady() ) {
UpdateMusicStream( state->music );
}
luaCallProcess();
luaCallDraw();
}
stateFree();
return 1;
}

2113
src/models.c Normal file

File diff suppressed because it is too large Load Diff

544
src/rgui.c Normal file
View File

@@ -0,0 +1,544 @@
#include "main.h"
#include "state.h"
#include "rgui.h"
#include "lua_core.h"
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
/*
## Gui - Global
*/
/*
> RL_GuiEnable()
Enable gui controls ( Global state )
*/
int lguiGuiEnable( lua_State *L ) {
GuiEnable();
return 1;
}
/*
> RL_GuiDisable()
Disable gui controls ( Global state )
*/
int lguiGuiDisable( lua_State *L ) {
GuiDisable();
return 1;
}
/*
> RL_GuiLock()
Lock gui controls ( Global state )
*/
int lguiGuiLock( lua_State *L ) {
GuiLock();
return 1;
}
/*
> RL_GuiUnlock()
Unlock gui controls ( Global state )
*/
int lguiGuiUnlock( lua_State *L ) {
GuiUnlock();
return 1;
}
/*
## Gui - Font
*/
/*
> success = RL_GuiSetFont( Font font )
Set gui custom font ( Global state )
- Failure return false
- Success return true
*/
int lguiGuiSetFont( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiSetFont( Font font )" );
lua_pushboolean( L, false );
return 1;
}
GuiSetFont( *state->fonts[ lua_tointeger( L, -1 ) ] );
lua_pushboolean( L, true );
return 1;
}
/*
## Gui - Container
*/
/*
> state = RL_GuiWindowBox( Rectangle bounds, string title )
Window Box control, shows a window that can be closed
- Failure return nil
- Success return bool
*/
int lguiGuiWindowBox( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiWindowBox( Rectangle bounds, string title )" );
lua_pushnil( L );
return 1;
}
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushboolean( L, GuiWindowBox( rect, text ) );
return 1;
}
/*
> success = RL_GuiPanel( Rectangle bounds )
Panel control, useful to group controls
- Failure return false
- Success return true
*/
int lguiGuiPanel( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiPanel( Rectangle bounds )" );
lua_pushboolean( L, false );
return 1;
}
Rectangle rect = uluaGetRectangle( L );
GuiPanel( rect );
lua_pushboolean( L, true );
return 1;
}
/*
> view, scroll = RL_GuiScrollPanel( Rectangle bounds, Rectangle content, Vector2 scroll )
Scroll Panel control
- Failure return false
- Success return Rectangle, Vector2
*/
int lguiGuiScrollPanel( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiScrollPanel( Rectangle bounds, Rectangle content, Vector2 scroll )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 scroll = uluaGetVector2( L );
lua_pop( L, 1 );
Rectangle content = uluaGetRectangle( L );
lua_pop( L, 1 );
Rectangle bounds = uluaGetRectangle( L );
uluaPushRectangle( L, GuiScrollPanel( bounds, content, &scroll ) );
uluaPushVector2( L, scroll );
return 2;
}
/*
## Gui - Basic
*/
/*
> success = RL_GuiLabel( Rectangle bounds, string text )
Label control, shows text
- Failure return false
- Success return true
*/
int lguiGuiLabel( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiLabel( Rectangle bounds, string text )" );
lua_pushboolean( L, false );
return 1;
}
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
GuiLabel( rect, text );
lua_pushboolean( L, true );
return 1;
}
/*
> clicked = RL_GuiButton( Rectangle bounds, string text )
Button control, returns true when clicked
- Failure return nil
- Success return boolean
*/
int lguiGuiButton( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiButton( Rectangle bounds, string text )" );
lua_pushnil( L );
return 1;
}
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushboolean( L, GuiButton( rect, text ) );
return 1;
}
/*
> active = RL_GuiToggle( Rectangle bounds, string text, bool active )
Toggle Button control, returns true when active
- Failure return nil
- Success return boolean
*/
int lguiGuiToggle( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isboolean( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiToggle( Rectangle bounds, string text, bool active )" );
lua_pushnil( L );
return 1;
}
bool checked = lua_toboolean( L, -1 );
lua_pop( L, 1 );
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushboolean( L, GuiToggle( rect, text, checked ) );
return 1;
}
/*
> active = RL_GuiCheckBox( Rectangle bounds, string text, bool checked )
Check Box control, returns true when active
- Failure return nil
- Success return boolean
*/
int lguiGuiCheckBox( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_isstring( L, -2 ) || !lua_isboolean( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiCheckBox( Rectangle bounds, string text, bool checked )" );
lua_pushnil( L );
return 1;
}
bool checked = lua_toboolean( L, -1 );
lua_pop( L, 1 );
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushboolean( L, GuiCheckBox( rect, text, checked ) );
return 1;
}
/*
> pressed, text = RL_GuiTextBox( Rectangle bounds, string text, int textSize, bool editMode )
Text Box control, updates input text
- Failure return nil
- Success return boolean, string
*/
int lguiGuiTextBox( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiTextBox( Rectangle bounds, string text, int textSize, bool editMode )" );
lua_pushnil( L );
return 1;
}
bool editMode = lua_toboolean( L, -1 );
lua_pop( L, 1 );
int textSize = lua_tointeger( L, -1 );
lua_pop( L, 1 );
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushboolean( L, GuiTextBox( rect, text, textSize, editMode ) );
lua_pushstring( L, text );
return 2;
}
/*
> pressed, text = RL_GuiTextBoxMulti( Rectangle bounds, string text, int textSize, bool editMode )
Text Box control with multiple lines
- Failure return nil
- Success return boolean, string
*/
int lguiGuiTextBoxMulti( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiTextBoxMulti( Rectangle bounds, string text, int textSize, bool editMode )" );
lua_pushnil( L );
return 1;
}
bool editMode = lua_toboolean( L, -1 );
lua_pop( L, 1 );
int textSize = lua_tointeger( L, -1 );
lua_pop( L, 1 );
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushboolean( L, GuiTextBoxMulti( rect, text, textSize, editMode ) );
lua_pushstring( L, text );
return 2;
}
/*
> pressed, value = RL_GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
Spinner control, returns selected value
- Failure return nil
- Success return boolean, int
*/
int lguiGuiSpinner( lua_State *L ) {
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isnumber( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiSpinner( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )" );
lua_pushnil( L );
return 1;
}
bool editMode = lua_toboolean( L, -1 );
lua_pop( L, 1 );
int maxValue = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int minValue = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int value = lua_tointeger( L, -1 );
lua_pop( L, 1 );
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushboolean( L, GuiSpinner( rect, text, &value, minValue, maxValue, editMode ) );
lua_pushinteger( L, value );
return 2;
}
/*
> pressed, value = RL_GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )
Value Box control, updates input text with numbers
- Failure return nil
- Success return boolean, int
*/
int lguiGuiValueBox( lua_State *L ) {
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isnumber( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiValueBox( Rectangle bounds, string text, int value, int minValue, int maxValue, bool editMode )" );
lua_pushnil( L );
return 1;
}
bool editMode = lua_toboolean( L, -1 );
lua_pop( L, 1 );
int maxValue = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int minValue = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int value = lua_tointeger( L, -1 );
lua_pop( L, 1 );
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushboolean( L, GuiValueBox( rect, text, &value, minValue, maxValue, editMode ) );
lua_pushinteger( L, value );
return 2;
}
/*
> value = RL_GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
Slider control, returns selected value
- Failure return nil
- Success return float
*/
int lguiGuiSlider( lua_State *L ) {
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiSlider( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" );
lua_pushnil( L );
return 1;
}
float maxValue = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float minValue = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float value = lua_tonumber( L, -1 );
lua_pop( L, 1 );
char textRight[ STRING_LEN ] = { '\0' };
strcpy( textRight, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
char textLeft[ STRING_LEN ] = { '\0' };
strcpy( textLeft, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushnumber( L, GuiSlider( rect, textLeft, textRight, value, minValue, maxValue ) );
return 1;
}
/*
> value = RL_GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
Slider Bar control, returns selected value
- Failure return nil
- Success return float
*/
int lguiGuiSliderBar( lua_State *L ) {
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiSliderBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" );
lua_pushnil( L );
return 1;
}
float maxValue = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float minValue = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float value = lua_tonumber( L, -1 );
lua_pop( L, 1 );
char textRight[ STRING_LEN ] = { '\0' };
strcpy( textRight, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
char textLeft[ STRING_LEN ] = { '\0' };
strcpy( textLeft, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushnumber( L, GuiSliderBar( rect, textLeft, textRight, value, minValue, maxValue ) );
return 1;
}
/*
> value = RL_GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )
Progress Bar control, shows current progress value
- Failure return nil
- Success return float
*/
int lguiGuiProgressBar( lua_State *L ) {
if ( !lua_istable( L, -6 ) || !lua_isstring( L, -5 ) || !lua_isstring( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiProgressBar( Rectangle bounds, string textLeft, string textRight, float value, float minValue, float maxValue )" );
lua_pushnil( L );
return 1;
}
float maxValue = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float minValue = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float value = lua_tonumber( L, -1 );
lua_pop( L, 1 );
char textRight[ STRING_LEN ] = { '\0' };
strcpy( textRight, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
char textLeft[ STRING_LEN ] = { '\0' };
strcpy( textLeft, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushnumber( L, GuiProgressBar( rect, textLeft, textRight, value, minValue, maxValue ) );
return 1;
}
/*
> value = RL_GuiScrollBar( Rectangle bounds, int value, int minValue, int maxValue )
Scroll Bar control
- Failure return nil
- Success return int
*/
int lguiGuiScrollBar( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiScrollBar( Rectangle bounds, int value, int minValue, int maxValue )" );
lua_pushnil( L );
return 1;
}
int maxValue = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int minValue = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int value = lua_tointeger( L, -1 );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushinteger( L, GuiScrollBar( rect, value, minValue, maxValue ) );
return 1;
}
/*
> pressed, item = RL_GuiDropdownBox( Rectangle bounds, string text, int active, bool editMode )
Dropdown Box control, returns selected item
- Failure return nil
- Success return bool, int
*/
int lguiGuiDropdownBox( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isboolean( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GuiDropdownBox( Rectangle bounds, string text, int active, bool editMode )" );
lua_pushnil( L );
return 1;
}
bool editMode = lua_toboolean( L, -1 );
lua_pop( L, 1 );
int active = lua_tointeger( L, -1 );
lua_pop( L, 1 );
char text[ STRING_LEN ] = { '\0' };
strcpy( text, lua_tostring( L, -1 ) );
lua_pop( L, 1 );
Rectangle rect = uluaGetRectangle( L );
lua_pushboolean( L, GuiDropdownBox( rect, text, &active, editMode ) );
lua_pushinteger( L, active );
return 2;
}

978
src/rmath.c Normal file
View File

@@ -0,0 +1,978 @@
#include "main.h"
#include "state.h"
#include "rmath.h"
#include "lua_core.h"
inline int imin( int a, int b ) {
return a < b ? a : b;
}
inline int imax( int a, int b ) {
return a > b ? a : b;
}
/*
## Math - Vector2
*/
/*
> result = RL_Vector2Add( Vector2 v1, Vector2 v2 )
Add two vectors (v1 + v2)
- Failure return false
- Success return Vector2
*/
int lmathVector2Add( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Add( Vector2 v1, Vector2 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
uluaPushVector2( L, Vector2Add( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector2Subtract( Vector2 v1, Vector2 v2 )
Subtract two vectors (v1 - v2)
- Failure return false
- Success return Vector2
*/
int lmathVector2Subtract( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Subtract( Vector2 v1, Vector2 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
uluaPushVector2( L, Vector2Subtract( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector2Multiply( Vector2 v1, Vector2 v2 )
Multiply vector by vector
- Failure return false
- Success return Vector2
*/
int lmathVector2Multiply( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Multiply( Vector2 v1, Vector2 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
uluaPushVector2( L, Vector2Multiply( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector2Length( vector2 vector )
Calculate vector length
- Failure return false
- Success return float
*/
int lmathVector2Length( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Length( vector2 v )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v = uluaGetVector2( L );
lua_pushnumber( L, Vector2Length( v ) );
return 1;
}
/*
> result = RL_Vector2DotProduct( Vector2 v1, Vector2 v2 )
Calculate two vectors dot product
- Failure return false
- Success return float
*/
int lmathVector2DotProduct( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2DotProduct( Vector2 v1, Vector2 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
lua_pushnumber( L, Vector2DotProduct( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector2Distance( Vector2 v1, Vector2 v2 )
Calculate distance between two vectors
- Failure return false
- Success return float
*/
int lmathVector2Distance( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Distance( Vector2 v1, Vector2 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
lua_pushnumber( L, Vector2Distance( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector2Angle( Vector2 v1, Vector2 v2 )
Calculate angle from two vectors
- Failure return false
- Success return float
*/
int lmathVector2Angle( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Angle( Vector2 v1, Vector2 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
lua_pushnumber( L, Vector2Angle( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector2Normalize( Vector2 v )
Normalize provided vector
- Failure return false
- Success return Vector2
*/
int lmathVector2Normalize( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Normalize( Vector2 v )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v = Vector2Normalize( uluaGetVector2( L ) );
uluaPushVector2( L, v );
return 1;
}
/*
> result = RL_Vector2Lerp( Vector2 v1, Vector2 v2, float amount )
Calculate linear interpolation between two vectors
- Failure return false
- Success return Vector2
*/
int lmathVector2Lerp( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Lerp( Vector2 v1, Vector2 v2, float amount )" );
lua_pushboolean( L, false );
return 1;
}
float amount = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
uluaPushVector2( L, Vector2Lerp( v1, v2, amount ) );
return 1;
}
/*
> result = RL_Vector2Reflect( Vector2 v, Vector2 normal )
Calculate reflected vector to normal
- Failure return false
- Success return Vector2
*/
int lmathVector2Reflect( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Reflect( Vector2 v, Vector2 normal )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
uluaPushVector2( L, Vector2Reflect( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector2Rotate( Vector2 v, float angle )
Rotate vector by angle
- Failure return false
- Success return Vector2
*/
int lmathVector2Rotate( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Rotate( Vector2 v, float angle )" );
lua_pushboolean( L, false );
return 1;
}
float degs = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 v = uluaGetVector2( L );
uluaPushVector2( L, Vector2Rotate( v, degs ) );
return 1;
}
/*
> result = RL_Vector2MoveTowards( Vector2 v, Vector2 target, float maxDistance )
Move Vector towards target
- Failure return false
- Success return Vector2
*/
int lmathVector2MoveTowards( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2MoveTowards( Vector2 v, Vector2 target, float maxDistance )" );
lua_pushboolean( L, false );
return 1;
}
float maxDistance = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
uluaPushVector2( L, Vector2MoveTowards( v1, v2, maxDistance ) );
return 1;
}
/*
## Math - Vector 3
*/
/*
> result = RL_Vector3CrossProduct( Vector3 v1, Vector3 v2 )
Add two vectors
- Failure return false
- Success return Vector3
*/
int lmathVector3Add( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Add( Vector3 v1, Vector3 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
uluaPushVector3( L, Vector3Add( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector3Subtract( Vector3 v1, Vector3 v2 )
Subtract two vectors
- Failure return false
- Success return Vector3
*/
int lmathVector3Subtract( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Subtract( Vector3 v1, Vector3 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
uluaPushVector3( L, Vector3Subtract( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector3Subtract( Vector3 v1, Vector3 v2 )
Multiply vector by vector
- Failure return false
- Success return Vector3
*/
int lmathVector3Multiply( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Multiply( Vector3 v1, Vector3 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
uluaPushVector3( L, Vector3Multiply( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector3CrossProduct( Vector3 v1, Vector3 v2 )
Calculate two vectors cross product
- Failure return false
- Success return Vector3
*/
int lmathVector3CrossProduct( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3CrossProduct( Vector3 v1, Vector3 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
uluaPushVector3( L, Vector3CrossProduct( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector3Perpendicular( Vector3 v )
Calculate one vector perpendicular vector
- Failure return false
- Success return Vector3
*/
int lmathVector3Perpendicular( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Perpendicular( Vector3 v )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v = uluaGetVector3( L );
uluaPushVector3( L, Vector3Perpendicular( v ) );
return 1;
}
/*
> result = RL_Vector3Length( Vector3 v )
Calculate one vector perpendicular vector
- Failure return false
- Success return float
*/
int lmathVector3Length( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Length( Vector3 v )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v = uluaGetVector3( L );
lua_pushnumber( L, Vector3Length( v ) );
return 1;
}
/*
> result = RL_Vector3LengthSqr( Vector3 v )
Calculate vector square length
- Failure return false
- Success return float
*/
int lmathVector3LengthSqr( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3LengthSqr( Vector3 v )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v = uluaGetVector3( L );
lua_pushnumber( L, Vector3LengthSqr( v ) );
return 1;
}
/*
> result = RL_Vector3DotProduct( Vector3 v1, Vector3 v2 )
Calculate two vectors dot product
- Failure return false
- Success return float
*/
int lmathVector3DotProduct( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3DotProduct( Vector3 v1, Vector3 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
lua_pushnumber( L, Vector3DotProduct( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector3Distance( Vector3 v1, Vector3 v2 )
Calculate distance between two vectors
- Failure return false
- Success return float
*/
int lmathVector3Distance( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Distance( Vector3 v1, Vector3 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
lua_pushnumber( L, Vector3Distance( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector3Normalize( Vector3 v )
Normalize provided vector
- Failure return false
- Success return Vector3
*/
int lmathVector3Normalize( lua_State *L ) {
/* Vector. */
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Normalize( Vector3 v )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v = uluaGetVector3( L );
uluaPushVector3( L, Vector3Normalize( v ) );
return 1;
}
/*
> v1, v2 = RL_Vector3OrthoNormalize( Vector3 v1, Vector3 v2 )
Orthonormalize provided vectors. Makes vectors normalized and orthogonal to each other.
Gram-Schmidt function implementation
- Failure return false
- Success return Vector3, Vector3
*/
int lmathVector3OrthoNormalize( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3OrthoNormalize( Vector3 v1, Vector3 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
Vector3OrthoNormalize( &v1, &v2 );
uluaPushVector3( L, v1 );
uluaPushVector3( L, v2 );
return 2;
}
/*
> result = RL_Vector3Transform( Vector3 v, Matrix mat )
Transforms a Vector3 by a given Matrix
- Failure return false
- Success return Vector3
*/
int lmathVector3Transform( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Transform( Vector3 v, Matrix mat )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v1 = uluaGetVector3( L );
lua_pop( L, 1 );
Matrix mat = uluaGetMatrix( L );
uluaPushVector3( L, Vector3Transform( v1, mat ) );
return 1;
}
/*
> result = RL_Vector3RotateByQuaternion( Vector3 v, Quaternion q )
Transform a vector by quaternion rotation
- Failure return false
- Success return Vector3
*/
int lmathVector3RotateByQuaternion( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3RotateByQuaternion( Vector3 v, Quaternion q )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v1 = uluaGetVector3( L );
lua_pop( L, 1 );
Quaternion q = uluaGetQuaternion( L );
uluaPushVector3( L, Vector3RotateByQuaternion( v1, q ) );
return 1;
}
/*
> result = RL_Vector3Lerp( Vector3 v1, Vector3 v2, float amount )
Calculate linear interpolation between two vectors
- Failure return false
- Success return Vector3
*/
int lmathVector3Lerp( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Lerp( Vector3 v1, Vector3 v2, float amount )" );
lua_pushboolean( L, false );
return 1;
}
float amount = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
uluaPushVector3( L, Vector3Lerp( v1, v2, amount ) );
return 1;
}
/*
> result = RL_Vector3Reflect( Vector3 v, Vector3 normal )
Calculate reflected vector to normal
- Failure return false
- Success return Vector3
*/
int lmathVector3Reflect( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Reflect( Vector3 v, Vector3 normal )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 normal = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
uluaPushVector3( L, Vector3Reflect( v1, normal ) );
return 1;
}
/*
## Math - Matrix
*/
/*
> result = RL_MatrixDeterminant( Matrix mat )
Compute matrix determinant
- Failure return false
- Success return float
*/
int lmathMatrixDeterminant( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixDeterminant( Matrix mat )" );
lua_pushboolean( L, false );
return 1;
}
Matrix mat = uluaGetMatrix( L );
lua_pushnumber( L, MatrixDeterminant( mat ) );
return 1;
}
/*
> result = RL_MatrixTranspose( Matrix mat )
Transposes provided matrix
- Failure return false
- Success return Matrix
*/
int lmathMatrixTranspose( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixTranspose( Matrix mat )" );
lua_pushboolean( L, false );
return 1;
}
Matrix mat = uluaGetMatrix( L );
uluaPushMatrix( L, MatrixTranspose( mat ) );
return 1;
}
/*
> result = RL_MatrixInvert( Matrix mat )
Invert provided matrix
- Failure return false
- Success return Matrix
*/
int lmathMatrixInvert( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixInvert( Matrix mat )" );
lua_pushboolean( L, false );
return 1;
}
Matrix mat = uluaGetMatrix( L );
uluaPushMatrix( L, MatrixInvert( mat ) );
return 1;
}
/*
> result = RL_MatrixNormalize( Matrix mat )
Normalize provided matrix
- Failure return false
- Success return Matrix
*/
int lmathMatrixNormalize( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixNormalize( Matrix mat )" );
lua_pushboolean( L, false );
return 1;
}
Matrix mat = uluaGetMatrix( L );
uluaPushMatrix( L, MatrixNormalize( mat ) );
return 1;
}
/*
> result = MatrixIdentity()
Get identity matrix
- Success return Matrix
*/
int lmathMatrixIdentity( lua_State *L ) {
uluaPushMatrix( L, MatrixIdentity() );
return 1;
}
/*
> result = RL_MatrixAdd( Matrix left, Matrix right )
Add two matrices
- Failure return false
- Success return Matrix
*/
int lmathMatrixAdd( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixAdd( Matrix left, Matrix right )" );
lua_pushboolean( L, false );
return 1;
}
Matrix mat2 = uluaGetMatrix( L );
lua_pop( L, 1 );
Matrix mat1 = uluaGetMatrix( L );
uluaPushMatrix( L, MatrixAdd( mat1, mat2 ) );
return 1;
}
/*
> result = RL_MatrixAdd( Matrix left, Matrix right )
Subtract two matrices (left - right)
- Failure return false
- Success return Matrix
*/
int lmathMatrixSubtract( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixSubtract( Matrix left, Matrix right )" );
lua_pushboolean( L, false );
return 1;
}
Matrix mat2 = uluaGetMatrix( L );
lua_pop( L, 1 );
Matrix mat1 = uluaGetMatrix( L );
uluaPushMatrix( L, MatrixSubtract( mat1, mat2 ) );
return 1;
}
/*
> result = RL_MatrixMultiply( Matrix left, Matrix right )
Get two matrix multiplication
- Failure return false
- Success return Matrix
*/
int lmathMatrixMultiply( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixMultiply( Matrix left, Matrix right )" );
lua_pushboolean( L, false );
return 1;
}
Matrix mat2 = uluaGetMatrix( L );
lua_pop( L, 1 );
Matrix mat1 = uluaGetMatrix( L );
uluaPushMatrix( L, MatrixMultiply( mat1, mat2 ) );
return 1;
}
/*
> result = RL_MatrixTranslate( Vector3 translate )
Get translation matrix
- Failure return false
- Success return Matrix
*/
int lmathMatrixTranslate( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixTranslate( Vector3 translate )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v = uluaGetVector3( L );
uluaPushMatrix( L, MatrixTranslate( v.x, v.y, v.z ) );
return 1;
}
/*
> result = RL_MatrixRotate( Vector3 axis, float angle )
Create rotation matrix from axis and angle. NOTE: Angle should be provided in radians
- Failure return false
- Success return Matrix
*/
int lmathMatrixRotate( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixRotate( Vector3 axis, float angle )" );
lua_pushboolean( L, false );
return 1;
}
float angle = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector3 axis = uluaGetVector3( L );
uluaPushMatrix( L, MatrixRotate( axis, angle ) );
return 1;
}
/*
> result = RL_MatrixScale( Vector3 scale )
Get scaling matrix
- Failure return false
- Success return Matrix
*/
int lmathMatrixScale( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixScale( Vector3 scale )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v = uluaGetVector3( L );
uluaPushMatrix( L, MatrixScale( v.x, v.y, v.z ) );
return 1;
}
/*
> result = RL_MatrixFrustum( double left, double right, double bottom, double top, double near, double far )
Get perspective projection matrix
- Failure return false
- Success return Matrix
*/
int lmathMatrixFrustum( lua_State *L ) {
if ( !lua_isnumber( L, -6 ) || !lua_isnumber( L, -5 ) || !lua_isnumber( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixFrustum( double left, double right, double bottom, double top, double near, double far )" );
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 );
uluaPushMatrix( L, MatrixFrustum( left, right, bottom, top, near, far ) );
return 1;
}
/*
> result = RL_MatrixPerspective( double fovy, double aspect, double near, double far )
Get perspective projection matrix
- Failure return false
- Success return Matrix
*/
int lmathMatrixPerspective( lua_State *L ) {
if ( !lua_isnumber( L, -4 ) || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixPerspective( double fovy, double aspect, double near, double far )" );
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 );
uluaPushMatrix( L, MatrixPerspective( fovy, aspect, near, far ) );
return 1;
}
/*
> result = RL_MatrixOrtho( double left, double right, double bottom, double top, double near, double far )
Get orthographic projection matrix
- Failure return false
- Success return Matrix
*/
int lmathMatrixOrtho( lua_State *L ) {
if ( !lua_isnumber( L, -6 ) || !lua_isnumber( L, -5 ) || !lua_isnumber( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixOrtho( double left, double right, double bottom, double top, double near, double far )" );
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 );
uluaPushMatrix( L, MatrixOrtho( left, right, bottom, top, near, far ) );
return 1;
}
/*
> result = RL_MatrixLookAt( Vector3 eye, Vector3 target, Vector3 up )
Get camera look-at matrix ( View matrix )
- Failure return false
- Success return Matrix
*/
int lmathMatrixLookAt( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MatrixLookAt( Vector3 eye, Vector3 target, Vector3 up )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 up = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 target = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 eye = uluaGetVector3( L );
uluaPushMatrix( L, MatrixLookAt( eye, target, up ) );
return 1;
}

457
src/shapes.c Normal file
View File

@@ -0,0 +1,457 @@
#include "main.h"
#include "shapes.h"
#include "lua_core.h"
/*
## Shapes - Drawing
*/
/*
> success = RL_DrawPixel( Vector2 pos, Color color )
Draw a pixel
- Failure return false
- Success return true
*/
int lshapesDrawPixel( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawPixel( Vector2 pos, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
Vector2 pos = uluaGetVector2( L );
DrawPixelV( pos, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawLine( Vector2 startPos, Vector2 endPos, float thickness, Color color )
Draw a line defining thickness
- Failure return false
- Success return true
*/
int lshapesDrawLine( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawLine( Vector2 startPos, Vector2 endPos, float thickness, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
float thickness = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 endPos = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 startPos = uluaGetVector2( L );
DrawLineEx( startPos, endPos, thickness, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawCircle( Vector2 center, float radius, Color color )
Draw a color-filled circle
- Failure return false
- Success return true
*/
int lshapesDrawCircle( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawCircle( Vector2 center, float radius, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
float radius = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 center = uluaGetVector2( L );
DrawCircleV( center, radius, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawCircleLines( Vector2 center, float radius, Color color )
Draw circle outline
- Failure return false
- Success return true
*/
int lshapesDrawCircleLines( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawCircleLines( Vector2 center, float radius, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
float radius = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 center = uluaGetVector2( L );
DrawCircleLines( center.x, center.y, radius, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawRectangle( Rectangle rec, Color color )
Draw a color-filled rectangle
- Failure return false
- Success return true
*/
int lshapesDrawRectangle( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawRectangle( Rectangle rec, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Rectangle rect = { 0, 0, 0, 0 };
Color color = { 0, 0, 0, 0 };
color = uluaGetColor( L );
lua_pop( L, 1 );
rect = uluaGetRectangle( L );
DrawRectangleRec( rect, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawRectanglePro( Rectangle rec, Vector2 origin, float rotation, Color color )
Draw a color-filled rectangle with pro parameters
- Failure return false
- Success return true
*/
int lshapesDrawRectanglePro( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawRectanglePro( Rectangle rec, Vector2 origin, float rotation, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
float rotation = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 origin = uluaGetVector2( L );
lua_pop( L, 1 );
Rectangle rec = uluaGetRectangle( L );
DrawRectanglePro( rec, origin, rotation, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawTriangle( Vector2 v1, Vector2 v2, Vector2 v3, Color color )
Draw a color-filled triangle ( Vertex in counter-clockwise order! )
- Failure return false
- Success return true
*/
int lshapesDrawTriangle( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTriangle( Vector2 v1, Vector2 v2, Vector2 v3, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
Vector2 v3 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
DrawTriangle( v1, v2, v3, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawTriangleLines( Vector2 v1, Vector2 v2, Vector2 v3, Color color )
Draw triangle outline ( Vertex in counter-clockwise order! )
- Failure return false
- Success return true
*/
int lshapesDrawTriangleLines( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTriangleLines( Vector2 v1, Vector2 v2, Vector2 v3, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
Vector2 v3 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
DrawTriangleLines( v1, v2, v3, color );
lua_pushboolean( L, true );
return 1;
}
/*
## Shapes - Collision
*/
/*
> collision = RL_CheckCollisionRecs( Rectangle rec1, Rectangle rec2 )
Check collision between two rectangles
- Failure return nil
- Success return bool
*/
int lshapesCheckCollisionRecs( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionRecs( Rectangle rec1, Rectangle rec2 )" );
lua_pushnil( L );
return 1;
}
Rectangle rect1 = uluaGetRectangle( L );
lua_pop( L, 1 );
Rectangle rect2 = uluaGetRectangle( L );
lua_pushboolean( L, CheckCollisionRecs( rect1, rect2 ) );
return 1;
}
/*
> collision = RL_CheckCollisionCircles( Vector2 center1, float radius1, Vector2 center2, float radius2 )
Check collision between two circles
- Failure return nil
- Success return bool
*/
int lshapesCheckCollisionCircles( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_isnumber( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionCircles( Vector2 center1, float radius1, Vector2 center2, float radius2 )" );
lua_pushnil( L );
return 1;
}
float radius2 = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 center2 = uluaGetVector2( L );
lua_pop( L, 1 );
float radius1 = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 center1 = uluaGetVector2( L );
lua_pushboolean( L, CheckCollisionCircles( center1, radius1, center2, radius2 ) );
return 1;
}
/*
> collision = RL_CheckCollisionCircleRec( Vector2 center, float radius, Rectangle rec )
Check collision between circle and rectangle
- Failure return nil
- Success return bool
*/
int lshapesCheckCollisionCircleRec( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionCircleRec( Vector2 center, float radius, Rectangle rec )" );
lua_pushnil( L );
return 1;
}
Rectangle rec = uluaGetRectangle( L );
lua_pop( L, 1 );
float radius = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 center = uluaGetVector2( L );
lua_pushboolean( L, CheckCollisionCircleRec( center, radius, rec ) );
return 1;
}
/*
> collision = RL_CheckCollisionPointRec( Vector2 point, Rectangle rec )
Check if point is inside rectangle
- Failure return nil
- Success return bool
*/
int lshapesCheckCollisionPointRec( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionPointRec( Vector2 point, Rectangle rec )" );
lua_pushnil( L );
return 1;
}
Rectangle rec = uluaGetRectangle( L );
lua_pop( L, 1 );
Vector2 point = uluaGetVector2( L );
lua_pushboolean( L, CheckCollisionPointRec( point, rec ) );
return 1;
}
/*
> collision = RL_CheckCollisionPointCircle( Vector2 point, Vector2 center, float radius )
Check if point is inside circle
- Failure return nil
- Success return bool
*/
int lshapesCheckCollisionPointCircle( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionPointCircle( Vector2 point, Vector2 center, float radius )" );
lua_pushnil( L );
return 1;
}
float radius = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 center = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 point = uluaGetVector2( L );
lua_pushboolean( L, CheckCollisionPointCircle( point, center, radius ) );
return 1;
}
/*
> collision = RL_CheckCollisionPointTriangle( Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3 )
Check if point is inside a triangle
- Failure return nil
- Success return bool
*/
int lshapesCheckCollisionPointTriangle( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionPointTriangle( Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3 )" );
lua_pushnil( L );
return 1;
}
Vector2 p3 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 p2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 p1 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 point = uluaGetVector2( L );
lua_pushboolean( L, CheckCollisionPointTriangle( point, p1, p2, p3 ) );
return 1;
}
/*
> collision, position = RL_CheckCollisionLines( Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2 )
Check the collision between two lines defined by two points each, returns collision point by reference
- Failure return nil
- Success return bool, Vector2
*/
int lshapesCheckCollisionLines( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionLines( Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2 )" );
lua_pushnil( L );
return 1;
}
Vector2 endPos2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 startPos2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 endPos1 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 startPos1 = uluaGetVector2( L );
Vector2 colPoint = { 0, 0 };
lua_pushboolean( L, CheckCollisionLines( startPos1, endPos1, startPos2, endPos2, &colPoint ) );
uluaPushVector2( L, colPoint );
return 2;
}
/*
> collision = RL_CheckCollisionPointLine( Vector2 point, Vector2 p1, Vector2 p2, int threshold )
Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
- Failure return nil
- Success return bool
*/
int lshapesCheckCollisionPointLine( lua_State *L ) {
if ( !lua_istable( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_CheckCollisionPointLine( Vector2 point, Vector2 p1, Vector2 p2, int threshold )" );
lua_pushnil( L );
return 1;
}
int threshold = lua_tointeger( L, -1 );
lua_pop( L, 1 );
Vector2 p2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 p1 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 point = uluaGetVector2( L );
lua_pushboolean( L, CheckCollisionPointLine( point, p1, p2, threshold ) );
return 1;
}
/*
> rectangle = RL_GetCollisionRec( Rectangle rec1, Rectangle rec2 )
Get collision rectangle for two rectangles collision
- Failure return nil
- Success return Rectangle
*/
int lshapesGetCollisionRec( lua_State *L ) {
/* Rectangle rec1, Rectangle rec2 */
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetCollisionRec( Rectangle rec1, Rectangle rec2 )" );
lua_pushnil( L );
return 1;
}
Rectangle rec2 = uluaGetRectangle( L );
lua_pop( L, 1 );
Rectangle rec1 = uluaGetRectangle( L );
uluaPushRectangle( L, GetCollisionRec( rec1, rec2 ) );
return 1;
}

194
src/state.c Normal file
View File

@@ -0,0 +1,194 @@
#include "main.h"
#include "state.h"
#include "lua_core.h"
#include "textures.h"
State *state;
bool stateInit( const char *exePath ) {
state = malloc( sizeof( State ) );
state->exePath = malloc( STRING_LEN * sizeof( char ) );
strncpy( state->exePath, exePath, STRING_LEN - 1 );
state->hasWindow = true;
state->run = true;
state->resolution = (Vector2){ 1024, 720 };
state->luaState = NULL;
state->targetFPS = 60;
state->textureSource = TEXTURE_SOURCE_TEXTURE;
/* Images. */
state->imageAlloc = ALLOC_PAGE_SIZE;
state->imageCount = 0;
state->images = malloc( state->imageAlloc * sizeof( Image* ) );
/* Textures. */
state->textureAlloc = ALLOC_PAGE_SIZE;
state->textureCount = 0;
state->textures = malloc( state->textureAlloc * sizeof( Texture2D* ) );
/* RenderTextures. */
state->renderTextureAlloc = ALLOC_PAGE_SIZE;
state->renderTextureCount = 0;
state->renderTextures = malloc( state->renderTextureAlloc * sizeof( RenderTexture2D* ) );
/* Fonts. */
state->fontAlloc = ALLOC_PAGE_SIZE;
state->fontCount = 1;
state->fonts = malloc( state->fontAlloc * sizeof( Font* ) );
/* Sounds. */
state->soundAlloc = ALLOC_PAGE_SIZE;
state->soundCount = 0;
state->sounds = malloc( state->soundAlloc * sizeof( Sound* ) );
/* Camera3D's. */
state->camera3DAlloc = ALLOC_PAGE_SIZE;
state->camera3DCount = 0;
state->camera3Ds = malloc( state->camera3DAlloc * sizeof( Camera3D* ) );
/* Meshes. */
state->meshAlloc = ALLOC_PAGE_SIZE;
state->meshCount = 0;
state->meshes = malloc( state->meshAlloc * sizeof( Mesh* ) );
/* Materials. */
state->materialAlloc = ALLOC_PAGE_SIZE;
state->materialCount = 1;
state->materials = malloc( state->materialAlloc * sizeof( Material* ) );
/* Models. */
state->modelAlloc = ALLOC_PAGE_SIZE;
state->modelCount = 0;
state->models = malloc( state->modelAlloc * sizeof( Model* ) );
/* ModelsAnimations. */
state->animationAlloc = ALLOC_PAGE_SIZE;
state->animationCount = 0;
state->animations = malloc( state->animationAlloc * sizeof( ModelAnimations* ) );
/* Shaders. */
state->shaderAlloc = ALLOC_PAGE_SIZE;
state->shaderCount = 0;
state->shaders = malloc( state->shaderAlloc * sizeof( Shader* ) );
for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
state->images[i] = NULL;
state->textures[i] = NULL;
state->renderTextures[i] = NULL;
state->sounds[i] = NULL;
state->camera3Ds[i] = NULL;
state->meshes[i] = NULL;
state->models[i] = NULL;
state->animations[i] = NULL;
state->shaders[i] = NULL;
/* The ones we want to save the first. */
if ( 0 < i ) {
state->fonts[i] = NULL;
state->materials[i] = NULL;
}
}
InitWindow( state->resolution.x, state->resolution.y, "ReiLua" );
/* Has to be after InitWindod where opengl context is created. */
state->materials[0] = malloc( sizeof( Material ) );
*state->materials[0] = LoadMaterialDefault();
state->fonts[0] = malloc( sizeof( Font ) );
*state->fonts[0] = GetFontDefault();
if ( !IsWindowReady() ) {
state->hasWindow = false;
state->run = false;
}
else {
SetTargetFPS( state->targetFPS );
}
InitAudioDevice();
state->run = luaInit();
return state->run;
}
void stateFree() {
for ( int i = 0; i < state->imageCount; ++i ) {
if ( state->images[i] != NULL ) {
UnloadImage( *state->images[i] );
free( state->images[i] );
}
}
for ( int i = 0; i < state->textureCount; ++i ) {
if ( state->textures[i] != NULL ) {
UnloadTexture( *state->textures[i] );
free( state->textures[i] );
}
}
for ( int i = 0; i < state->renderTextureCount; ++i ) {
if ( state->renderTextures[i] != NULL ) {
UnloadRenderTexture( *state->renderTextures[i] );
free( state->renderTextures[i] );
}
}
for ( int i = 0; i < state->fontCount; ++i ) {
if ( state->fonts[i] != NULL ) {
UnloadFont( *state->fonts[i] );
free( state->fonts[i] );
}
}
for ( int i = 0; i < state->soundCount; ++i ) {
if ( state->sounds[i] != NULL ) {
UnloadSound( *state->sounds[i] );
free( state->sounds[i] );
}
}
for ( int i = 0; i < state->camera3DCount; ++i ) {
if ( state->camera3Ds[i] != NULL ) {
free( state->camera3Ds[i] );
}
}
for ( int i = 0; i < state->modelCount; ++i ) {
if ( state->models[i] != NULL ) {
// UnloadModel( *state->models[i] );
UnloadModelKeepMeshes( *state->models[i] );
free( state->models[i] );
}
}
for ( int i = 0; i < state->meshCount; ++i ) {
if ( state->meshes[i] != NULL ) {
UnloadMesh( *state->meshes[i] );
free( state->meshes[i] );
}
}
for ( int i = 0; i < state->materialCount; ++i ) {
if ( state->materials[i] != NULL ) {
UnloadMaterial( *state->materials[i] );
free( state->materials[i] );
}
}
for ( int i = 0; i < state->animationCount; ++i ) {
if ( state->animations[i] != NULL ) {
UnloadModelAnimations( state->animations[i]->animations, state->animations[i]->animCount );
free( state->animations[i] );
}
}
for ( int i = 0; i < state->shaderCount; ++i ) {
if ( state->shaders[i] != NULL ) {
UnloadShader( *state->shaders[i] );
free( state->shaders[i] );
}
}
if ( IsAudioDeviceReady() ) {
CloseAudioDevice();
UnloadMusicStream( state->music );
}
if ( state->hasWindow ) {
CloseWindow();
}
if ( state->luaState != NULL ) {
lua_close( state->luaState );
}
free( state->images );
free( state->textures );
free( state->renderTextures );
free( state->fonts );
free( state->sounds );
free( state->camera3Ds );
free( state->meshes );
free( state->materials );
free( state->models );
free( state->animations );
free( state->shaders );
free( state );
}

102
src/text.c Normal file
View File

@@ -0,0 +1,102 @@
#include "main.h"
#include "state.h"
#include "text.h"
#include "lua_core.h"
static void checkFontRealloc( int i ) {
if ( i == state->fontCount ) {
state->fontCount++;
}
if ( state->fontCount == state->fontAlloc ) {
state->fontAlloc += ALLOC_PAGE_SIZE;
state->fonts = realloc( state->fonts, state->fontAlloc * sizeof( Font* ) );
for ( i = state->fontCount; i < state->fontAlloc; i++ ) {
state->fonts[i] = NULL;
}
}
}
bool validFont( size_t id ) {
if ( id < 0 || state->fontCount < id || state->fonts[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid font", id );
return false;
}
else {
return true;
}
}
/*
## Text - Loading
*/
/*
> font = RL_LoadFont( string fileName )
Load font from file into GPU memory ( VRAM )
- Failure return -1
- Success return int
*/
int lmodelsLoadFont( lua_State *L ) {
if ( !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadFont( string fileName )" );
lua_pushinteger( L, -1 );
return 1;
}
int i = 0;
for ( i = 0; i < state->fontCount; i++ ) {
if ( state->fonts[i] == NULL ) {
break;
}
}
state->fonts[i] = malloc( sizeof( Font ) );
*state->fonts[i] = LoadFont( lua_tostring( L, -1 ) );
lua_pushinteger( L, i );
checkFontRealloc( i );
return 1;
}
/*
## Text - Draw
*/
/*
> success = RL_DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
Draw text using font and additional parameters
- Failure return false
- Success return true
*/
int ltextDrawText( lua_State *L ) {
if ( !lua_isnumber( L, -6 ) || !lua_isstring( L, -5 ) || !lua_istable( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
float spacing = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float fontSize = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 position = uluaGetVector2( L );
lua_pop( L, 1 );
size_t fontId = lua_tointeger( L, -2 );
if ( !validFont( fontId ) ) {
lua_pushboolean( L, false );
return 1;
}
DrawTextEx( *state->fonts[ fontId ], lua_tostring( L, -1 ), position, fontSize, spacing, color );
lua_pushboolean( L, true );
return 1;
}

1057
src/textures.c Normal file

File diff suppressed because it is too large Load Diff