summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md317
-rw-r--r--ReiLua_API.lua361
-rw-r--r--changelog2
-rw-r--r--examples/basic_lighting/main.lua2
-rw-r--r--examples/heightmap/main.lua6
-rw-r--r--examples/iqm_test/main.lua20
-rw-r--r--examples/lightmap/main.lua12
-rw-r--r--examples/window/main.lua2
-rw-r--r--include/lua_core.h4
-rw-r--r--include/models.h4
-rw-r--r--include/state.h22
-rw-r--r--src/lua_core.c126
-rw-r--r--src/models.c1514
-rw-r--r--src/state.c63
-rw-r--r--src/text.c2
-rw-r--r--src/textures.c36
16 files changed, 647 insertions, 1846 deletions
diff --git a/API.md b/API.md
index 216ddb5..f09cf22 100644
--- a/API.md
+++ b/API.md
@@ -3515,12 +3515,9 @@ Draw a source image within a destination image (Tint applied to source)
---
-> success = RL.ImageDrawTextEx( Image dst, Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
+> RL.ImageDrawTextEx( Image dst, Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
-Draw text ( Custom sprite font ) within an image ( Destination )
-
-- Failure return false
-- Success return true
+Draw text (Custom sprite font) within an image (Destination)
---
@@ -3868,7 +3865,7 @@ Load font from file into GPU memory (VRAM)
---
-> font = RL.LoadFontEx( string fileName, int fontSize, int fontChars{} )
+> font = RL.LoadFontEx( string fileName, int fontSize, int{} fontChars )
Load font from file with extended parameters. Loading the default character set
@@ -3955,171 +3952,117 @@ Get font texture atlas containing the glyphs.
---
-> success = RL.DrawLine3D( Vector3 startPos, Vector3 endPos, Color color )
+> RL.DrawLine3D( Vector3 startPos, Vector3 endPos, Color color )
Draw a line in 3D world space
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawPoint3D( Vector3 position, Color color )
+> RL.DrawPoint3D( Vector3 position, Color color )
Draw a point in 3D space, actually a small line
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawCircle3D( Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color )
+> RL.DrawCircle3D( Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color )
Draw a circle in 3D world space
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawTriangle3D( Vector3 v1, Vector3 v2, Vector3 v3, Color color )
+> RL.DrawTriangle3D( Vector3 v1, Vector3 v2, Vector3 v3, Color color )
-Draw a color-filled triangle ( Vertex in counter-clockwise order! )
-
-- Failure return false
-- Success return true
+Draw a color-filled triangle (Vertex in counter-clockwise order!)
---
-> success = RL.DrawCube( Vector3 position, Vector3 size, Color color )
+> RL.DrawCube( Vector3 position, Vector3 size, Color color )
Draw cube
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawCubeWires( Vector3 position, Vector3 size, Color color )
+> RL.DrawCubeWires( Vector3 position, Vector3 size, Color color )
Draw cube wires
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawSphere( Vector3 centerPos, float radius, Color color )
+> RL.DrawSphere( Vector3 centerPos, float radius, Color color )
Draw sphere
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawSphereEx( Vector3 centerPos, float radius, int rings, int slices, Color color )
+> RL.DrawSphereEx( Vector3 centerPos, float radius, int rings, int slices, Color color )
Draw sphere with extended parameters
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawSphereWires( Vector3 centerPos, float radius, int rings, int slices, Color color )
+> RL.DrawSphereWires( Vector3 centerPos, float radius, int rings, int slices, Color color )
Draw sphere wires
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawCylinder( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )
+> RL.DrawCylinder( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )
Draw a cylinder/cone
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawCylinderEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )
+> RL.DrawCylinderEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )
Draw a cylinder with base at startPos and top at endPos
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawCylinderWires( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )
+> RL.DrawCylinderWires( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )
Draw a cylinder/cone wires
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawCylinderWiresEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )
+> RL.DrawCylinderWiresEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )
Draw a cylinder wires with base at startPos and top at endPos
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
+> RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
Draw a capsule with the center of its sphere caps at startPos and endPos
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
+> RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
Draw capsule wireframe with the center of its sphere caps at startPos and endPos
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawPlane( Vector3 centerPos, Vector2 size, Color color )
+> RL.DrawPlane( Vector3 centerPos, Vector2 size, Color color )
Draw a plane XZ
-- Failure return false
-- Success return true
-
---
> RL.DrawQuad3DTexture( Texture texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )
-Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ).
+Draw 3D textured quad. (Texture coordinates opengl style 0.0 - 1.0).
---
-> success = RL.DrawRay( Ray ray, Color color )
+> RL.DrawRay( Ray ray, Color color )
Draw a ray line
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawGrid( int slices, float spacing )
+> RL.DrawGrid( int slices, float spacing )
-Draw a grid ( Centered at ( 0, 0, 0 ) )
-
-- Failure return false
-- Success return true
+Draw a grid (Centered at ( 0, 0, 0 ))
---
@@ -4131,17 +4074,15 @@ Draw a grid ( Centered at ( 0, 0, 0 ) )
Generate polygonal mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
---
> mesh = RL.GenMeshPlane( float width, float length, int resX, int resZ )
-Generate plane mesh ( With subdivisions )
+Generate plane mesh (With subdivisions)
-- Failure return -1
-- Success return int
+- Success return Mesh
---
@@ -4149,17 +4090,15 @@ Generate plane mesh ( With subdivisions )
Generate cuboid mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
---
> mesh = RL.GenMeshSphere( float radius, int rings, int slices )
-Generate sphere mesh ( Standard sphere )
+Generate sphere mesh (Standard sphere)
-- Failure return -1
-- Success return int
+- Success return Mesh
---
@@ -4167,8 +4106,7 @@ Generate sphere mesh ( Standard sphere )
Generate cylinder mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
---
@@ -4176,8 +4114,7 @@ Generate cylinder mesh
Generate cone/pyramid mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
---
@@ -4185,8 +4122,7 @@ Generate cone/pyramid mesh
Generate torus mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
---
@@ -4194,8 +4130,7 @@ Generate torus mesh
Generate torus mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
---
@@ -4203,55 +4138,35 @@ Generate torus mesh
Generate heightmap mesh from image data
-- Failure return -1
-- Success return int
+- Success return Mesh
---
-> mesh = RL.GenMeshCustom( Mesh{} mesh, bool dynamic )
+> mesh = RL.GenMeshCustom( Mesh{} meshData, bool dynamic )
-Generate custom mesh from vertex attribute data and uploads it into a VAO ( if supported ) and VBO
+Generate custom mesh from vertex attribute data and uploads it into a VAO (if supported) and VBO
-- Failure return -1
-- Success return int
+- Success return Mesh
---
-> success = RL.UpdateMesh( Mesh mesh, Mesh{} updatedMesh )
+> RL.UpdateMesh( Mesh mesh, Mesh{} meshData )
Update mesh vertex data in GPU.
Note! Mainly intented to be used with custom meshes.
-- Failure return false
-- Success return true
-
---
-> success = RL.UnloadMesh( Mesh mesh )
-
-Unload mesh data from CPU and GPU
-
-- Failure return false
-- Success return true
-
----
-
-> success = RL.DrawMesh( Mesh mesh, Material material, Matrix transform )
+> RL.DrawMesh( Mesh mesh, Material material, Matrix transform )
Draw a 3d mesh with material and transform
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawMeshInstanced( Mesh mesh, Material material, Matrix{} transforms, int instances )
+> RL.DrawMeshInstanced( Mesh mesh, Material material, Matrix{} transforms, int instances )
Draw multiple mesh instances with material and different transforms
-- Failure return false
-- Success return true
-
---
> success = RL.SetMeshColor( Mesh mesh, Color color )
@@ -4268,8 +4183,7 @@ NOTE: Currently only works on custom mesh
Export mesh data to file, returns true on success
-- Failure return false
-- Success return true
+- Success return bool
---
@@ -4277,18 +4191,14 @@ Export mesh data to file, returns true on success
Compute mesh bounding box limits
-- Failure return false
- Success return BoundingBox
---
-> success = RL.GenMeshTangents( Mesh mesh )
+> RL.GenMeshTangents( Mesh mesh )
Compute mesh tangents
-- Failure return false
-- Success return true
-
---
## Models - Material
@@ -4299,50 +4209,34 @@ Compute mesh tangents
Load default material
-- Success return int
+- Success return Material
---
-> material = RL.CreateMaterial( Material{} material )
+> material = RL.CreateMaterial( Material{} materialData )
Load material from table. See material table definition
-- Failure return false
-- Success return int
-
----
-
-> success = RL.UnloadMaterial( Material material )
-
-Unload material from GPU memory ( VRAM )
-
-- Failure return false
-- Success return true
+- Success return Material
---
> RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )
-Set texture for a material map type ( MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS... )
+Set texture for a material map type (MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS...)
---
-> success = RL.SetMaterialColor( Material material, int mapType, Color color )
+> RL.SetMaterialColor( Material material, int mapType, Color color )
Set color for a material map type
-- Failure return false
-- Success return true
-
---
-> success = RL.SetMaterialValue( Material material, int mapType, float value )
+> RL.SetMaterialValue( Material material, int mapType, float value )
Set value for a material map type
-- Failure return false
-- Success return true
-
---
> RL.SetMaterialShader( Material material, Shader shader )
@@ -4351,56 +4245,48 @@ Set shader for material
---
-> success = RL.SetMaterialParams( Material material, float{} params )
+> RL.SetMaterialParams( Material material, float{} params )
-Set material generic parameters ( if required )
-
-- Failure return false
-- Success return true
+Set material generic parameters (if required)
---
> texture = RL.GetMaterialTexture( Material material, int mapType )
-Get texture from material map type. Returns -1 if no texture.
+Get texture from material map type. Returns -1 if no texture
-- Failure return false
-- Success return int
+- Success return Texture
---
> color = RL.GetMaterialColor( Material material, int mapType )
-Get color from material map type.
+Get color from material map type
-- Failure return false
- Success return Color
---
> value = RL.GetMaterialValue( Material material, int mapType )
-Get color from material map type.
+Get color from material map type
-- Failure return false
- Success return float
---
> shader = RL.GetMaterialShader( Material material )
-Get material shader. Returns -1 if no shader.
+Get material shader
-- Failure return false
- Success return Shader
---
> params = RL.GetMaterialParams( Material material )
-Get material parameters.
+Get material parameters
-- Failure return false
- Success return float{}
---
@@ -4411,64 +4297,42 @@ Get material parameters.
> model = RL.LoadModel( string fileName )
-Load model from files ( Meshes and materials )
+Load model from files (Meshes and materials)
-- Failure return -1
-- Success return int
+- Failure return nil
+- Success return Model
---
> model = RL.LoadModelFromMesh( Mesh mesh )
-Load model from generated mesh ( Default material )
+Load model from generated mesh (Default material)
-- Failure return -1
-- Success return int
+- Success return Model
---
-> success = RL.UnloadModel( Model model )
-
-Unload model ( Including meshes ) from memory ( RAM and/or VRAM )
+> RL.DrawModel( Model model, Vector3 position, float scale, Color tint )
-- Failure return false
-- Success return true
+Draw a model (With texture if set)
---
-> success = RL.DrawModel( Model model, Vector3 position, float scale, Color tint )
-
-Draw a model ( With texture if set )
-
-- Failure return false
-- Success return true
-
----
-
-> success = RL.DrawModelEx( Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint )
+> RL.DrawModelEx( Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint )
Draw a model with extended parameters
-- Failure return false
-- Success return true
-
---
-> success = RL.SetModelMaterial( Model model, Material modelMaterial, Material material )
-
-Copies material to model material. ( Model material is the material id in models. Material can be deleted if not used elsewhere )
+> RL.SetModelMaterial( Model model, Material modelMaterial, Material material )
-- Failure return false
-- Success return true
+Copies material to model material. (Model material is the material id in models.)
---
-> success = RL.SetModelMeshMaterial( Model model, int meshId, int materialId )
-
-Set material for a mesh ( Mesh and material on this model )
+> RL.SetModelMeshMaterial( Model model, int meshId, int materialId )
-- Failure return false
-- Success return true
+Set material for a mesh (Mesh and material on this model)
---
@@ -4490,20 +4354,16 @@ Draw a billboard texture defined by source and rotation
---
-> success = RL.SetModelTransform( Model model, Matrix transform )
+> RL.SetModelTransform( Model model, Matrix transform )
Set model transform matrix
-- Failure return false
-- Success return true
-
---
> transform = RL.GetModelTransform( Model model )
Get model transform matrix
-- Failure return false
- Success return Matrix
---
@@ -4512,56 +4372,41 @@ Get model transform matrix
---
-> animations, animationCount = RL.LoadModelAnimations( string fileName )
+> animations = RL.LoadModelAnimations( string fileName )
Load model animations from file
-- Failure return -1
-- Success return int, int
+- Failure return nil
+- Success return ModelAnimations{}
---
-> success = RL.UpdateModelAnimation( Model model, ModelAnimations animations, int animation, int frame )
+> RL.UpdateModelAnimation( Model model, ModelAnimation animation, int frame )
Update model animation pose
-- Failure return false
-- Success return true
-
----
-
-> success = RL.UnloadModelAnimations( ModelAnimations animations )
-
-Unload animation data
-
-- Failure return false
-- Success return true
-
---
-> valid = RL.IsModelAnimationValid( Model model, ModelAnimations animations )
+> valid = RL.IsModelAnimationValid( Model model, ModelAnimation animation )
Check model animation skeleton match
-- Failure return nil
- Success return bool
---
-> boneCount = RL.GetModelAnimationBoneCount( ModelAnimations animations, int animation )
+> boneCount = RL.GetModelAnimationBoneCount( ModelAnimation animation )
Return modelAnimation bone count
-- Failure return false
- Success return int
---
-> frameCount = RL.GetModelAnimationFrameCount( ModelAnimations animations, int animation )
+> frameCount = RL.GetModelAnimationFrameCount( ModelAnimation animation )
Return modelAnimation frame count
-- Failure return false
- Success return int
---
@@ -4574,7 +4419,6 @@ Return modelAnimation frame count
Check collision between two spheres
-- Failure return nil
- Success return bool
---
@@ -4583,7 +4427,6 @@ Check collision between two spheres
Check collision between two bounding boxes
-- Failure return nil
- Success return bool
---
@@ -4592,7 +4435,6 @@ Check collision between two bounding boxes
Check collision between box and sphere
-- Failure return nil
- Success return bool
---
@@ -4601,7 +4443,6 @@ Check collision between box and sphere
Get collision info between ray and sphere. ( RayCollision is Lua table of { hit, distance, point, normal } )
-- Failure return nil
- Success return RayCollision
---
@@ -4610,7 +4451,6 @@ Get collision info between ray and sphere. ( RayCollision is Lua table of { hit,
Get collision info between ray and box
-- Failure return nil
- Success return RayCollision
---
@@ -4619,7 +4459,6 @@ Get collision info between ray and box
Get collision info between ray and mesh
-- Failure return nil
- Success return RayCollision
---
@@ -4628,7 +4467,6 @@ Get collision info between ray and mesh
Get collision info between ray and triangle
-- Failure return nil
- Success return RayCollision
---
@@ -4637,7 +4475,6 @@ Get collision info between ray and triangle
Get collision info between ray and quad
-- Failure return nil
- Success return RayCollision
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 254dd16..f9e6038 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -2503,9 +2503,7 @@ function RL.ImageDrawRectangleLines( dst, rec, thick, color ) end
---@return any RL.ImageDraw
function RL.ImageDraw( dst, src, srcRec, dstRec, tint ) end
----Draw text ( Custom sprite font ) within an image ( Destination )
----- Failure return false
----- Success return true
+---Draw text (Custom sprite font) within an image (Destination)
---@param dst any
---@param font any
---@param text string
@@ -2513,8 +2511,8 @@ function RL.ImageDraw( dst, src, srcRec, dstRec, tint ) end
---@param fontSize number
---@param spacing number
---@param tint table
----@return any success
-function RL.ImageDrawTextEx( dst, font, text, position, fontSize, spacing, tint ) end
+---@return any RL.ImageDrawTextEx
+function RL.ImageDrawTextEx( dst, font, text, position, fontSize, spacing, tint ) end
-- Textures - Image Configuration
@@ -2810,9 +2808,9 @@ function RL.LoadFont( fileName ) end
---- Success return Font
---@param fileName string
---@param fontSize integer
----@param fontChars{} integer
+---@param fontChars any
---@return any font
-function RL.LoadFontEx( fileName, fontSize, fontChars{} ) end
+function RL.LoadFontEx( fileName, fontSize, fontChars ) end
---Load font from Image ( XNA style)
---- Success return Font
@@ -2889,174 +2887,142 @@ function RL.GetFontTexture( font ) end
-- Models - Basic
---Draw a line in 3D world space
----- Failure return false
----- Success return true
---@param startPos table
---@param endPos table
---@param color table
----@return any success
-function RL.DrawLine3D( startPos, endPos, color ) end
+---@return any RL.DrawLine3D
+function RL.DrawLine3D( startPos, endPos, color ) end
---Draw a point in 3D space, actually a small line
----- Failure return false
----- Success return true
---@param position table
---@param color table
----@return any success
-function RL.DrawPoint3D( position, color ) end
+---@return any RL.DrawPoint3D
+function RL.DrawPoint3D( position, color ) end
---Draw a circle in 3D world space
----- Failure return false
----- Success return true
---@param center table
---@param radius number
---@param rotationAxis table
---@param rotationAngle number
---@param color table
----@return any success
-function RL.DrawCircle3D( center, radius, rotationAxis, rotationAngle, color ) end
+---@return any RL.DrawCircle3D
+function RL.DrawCircle3D( center, radius, rotationAxis, rotationAngle, color ) end
----Draw a color-filled triangle ( Vertex in counter-clockwise order! )
----- Failure return false
----- Success return true
+---Draw a color-filled triangle (Vertex in counter-clockwise order!)
---@param v1 table
---@param v2 table
---@param v3 table
---@param color table
----@return any success
-function RL.DrawTriangle3D( v1, v2, v3, color ) end
+---@return any RL.DrawTriangle3D
+function RL.DrawTriangle3D( v1, v2, v3, color ) end
---Draw cube
----- Failure return false
----- Success return true
---@param position table
---@param size table
---@param color table
----@return any success
-function RL.DrawCube( position, size, color ) end
+---@return any RL.DrawCube
+function RL.DrawCube( position, size, color ) end
---Draw cube wires
----- Failure return false
----- Success return true
---@param position table
---@param size table
---@param color table
----@return any success
-function RL.DrawCubeWires( position, size, color ) end
+---@return any RL.DrawCubeWires
+function RL.DrawCubeWires( position, size, color ) end
---Draw sphere
----- Failure return false
----- Success return true
---@param centerPos table
---@param radius number
---@param color table
----@return any success
-function RL.DrawSphere( centerPos, radius, color ) end
+---@return any RL.DrawSphere
+function RL.DrawSphere( centerPos, radius, color ) end
---Draw sphere with extended parameters
----- Failure return false
----- Success return true
---@param centerPos table
---@param radius number
---@param rings integer
---@param slices integer
---@param color table
----@return any success
-function RL.DrawSphereEx( centerPos, radius, rings, slices, color ) end
+---@return any RL.DrawSphereEx
+function RL.DrawSphereEx( centerPos, radius, rings, slices, color ) end
---Draw sphere wires
----- Failure return false
----- Success return true
---@param centerPos table
---@param radius number
---@param rings integer
---@param slices integer
---@param color table
----@return any success
-function RL.DrawSphereWires( centerPos, radius, rings, slices, color ) end
+---@return any RL.DrawSphereWires
+function RL.DrawSphereWires( centerPos, radius, rings, slices, color ) end
---Draw a cylinder/cone
----- Failure return false
----- Success return true
---@param position table
---@param radiusTop number
---@param radiusBottom number
---@param height number
---@param slices integer
---@param color table
----@return any success
-function RL.DrawCylinder( position, radiusTop, radiusBottom, height, slices, color ) end
+---@return any RL.DrawCylinder
+function RL.DrawCylinder( position, radiusTop, radiusBottom, height, slices, color ) end
---Draw a cylinder with base at startPos and top at endPos
----- Failure return false
----- Success return true
---@param startPos table
---@param endPos table
---@param startRadius number
---@param endRadius number
---@param sides integer
---@param color table
----@return any success
-function RL.DrawCylinderEx( startPos, endPos, startRadius, endRadius, sides, color ) end
+---@return any RL.DrawCylinderEx
+function RL.DrawCylinderEx( startPos, endPos, startRadius, endRadius, sides, color ) end
---Draw a cylinder/cone wires
----- Failure return false
----- Success return true
---@param position table
---@param radiusTop number
---@param radiusBottom number
---@param height number
---@param slices integer
---@param color table
----@return any success
-function RL.DrawCylinderWires( position, radiusTop, radiusBottom, height, slices, color ) end
+---@return any RL.DrawCylinderWires
+function RL.DrawCylinderWires( position, radiusTop, radiusBottom, height, slices, color ) end
---Draw a cylinder wires with base at startPos and top at endPos
----- Failure return false
----- Success return true
---@param startPos table
---@param endPos table
---@param startRadius number
---@param endRadius number
---@param sides integer
---@param color table
----@return any success
-function RL.DrawCylinderWiresEx( startPos, endPos, startRadius, endRadius, sides, color ) end
+---@return any RL.DrawCylinderWiresEx
+function RL.DrawCylinderWiresEx( startPos, endPos, startRadius, endRadius, sides, color ) end
---Draw a capsule with the center of its sphere caps at startPos and endPos
----- Failure return false
----- Success return true
---@param startPos table
---@param endPos table
---@param radius number
---@param slices integer
---@param rings integer
---@param color table
----@return any success
-function RL.DrawCapsule( startPos, endPos, radius, slices, rings, color ) end
+---@return any RL.DrawCapsule
+function RL.DrawCapsule( startPos, endPos, radius, slices, rings, color ) end
---Draw capsule wireframe with the center of its sphere caps at startPos and endPos
----- Failure return false
----- Success return true
---@param startPos table
---@param endPos table
---@param radius number
---@param slices integer
---@param rings integer
---@param color table
----@return any success
-function RL.DrawCapsuleWires( startPos, endPos, radius, slices, rings, color ) end
+---@return any RL.DrawCapsuleWires
+function RL.DrawCapsuleWires( startPos, endPos, radius, slices, rings, color ) end
---Draw a plane XZ
----- Failure return false
----- Success return true
---@param centerPos table
---@param size table
---@param color table
----@return any success
-function RL.DrawPlane( centerPos, size, color ) end
+---@return any RL.DrawPlane
+function RL.DrawPlane( centerPos, size, color ) end
----Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ).
+---Draw 3D textured quad. (Texture coordinates opengl style 0.0 - 1.0).
---@param texture any
---@param vertices any
---@param texCoords any
@@ -3065,34 +3031,28 @@ function RL.DrawPlane( centerPos, size, color ) end
function RL.DrawQuad3DTexture( texture, vertices, texCoords, colors ) end
---Draw a ray line
----- Failure return false
----- Success return true
---@param ray any
---@param color table
----@return any success
-function RL.DrawRay( ray, color ) end
+---@return any RL.DrawRay
+function RL.DrawRay( ray, color ) end
----Draw a grid ( Centered at ( 0, 0, 0 ) )
----- Failure return false
----- Success return true
+---Draw a grid (Centered at ( 0, 0, 0 ))
---@param slices integer
---@param spacing number
----@return any success
-function RL.DrawGrid( slices, spacing ) end
+---@return any RL.DrawGrid
+function RL.DrawGrid( slices, spacing ) end
-- Models - Mesh
---Generate polygonal mesh
----- Failure return -1
----- Success return int
+---- Success return Mesh
---@param sides integer
---@param radius number
---@return any mesh
function RL.GenMeshPoly( sides, radius ) end
----Generate plane mesh ( With subdivisions )
----- Failure return -1
----- Success return int
+---Generate plane mesh (With subdivisions)
+---- Success return Mesh
---@param width number
---@param length number
---@param resX integer
@@ -3101,15 +3061,13 @@ function RL.GenMeshPoly( sides, radius ) end
function RL.GenMeshPlane( width, length, resX, resZ ) end
---Generate cuboid mesh
----- Failure return -1
----- Success return int
+---- Success return Mesh
---@param size table
---@return any mesh
function RL.GenMeshCube( size ) end
----Generate sphere mesh ( Standard sphere )
----- Failure return -1
----- Success return int
+---Generate sphere mesh (Standard sphere)
+---- Success return Mesh
---@param radius number
---@param rings integer
---@param slices integer
@@ -3117,8 +3075,7 @@ function RL.GenMeshCube( size ) end
function RL.GenMeshSphere( radius, rings, slices ) end
---Generate cylinder mesh
----- Failure return -1
----- Success return int
+---- Success return Mesh
---@param radius number
---@param height number
---@param slices integer
@@ -3126,8 +3083,7 @@ function RL.GenMeshSphere( radius, rings, slices ) end
function RL.GenMeshCylinder( radius, height, slices ) end
---Generate cone/pyramid mesh
----- Failure return -1
----- Success return int
+---- Success return Mesh
---@param radius number
---@param height number
---@param slices integer
@@ -3135,8 +3091,7 @@ function RL.GenMeshCylinder( radius, height, slices ) end
function RL.GenMeshCone( radius, height, slices ) end
---Generate torus mesh
----- Failure return -1
----- Success return int
+---- Success return Mesh
---@param radius number
---@param size number
---@param radSeg integer
@@ -3145,8 +3100,7 @@ function RL.GenMeshCone( radius, height, slices ) end
function RL.GenMeshTorus( radius, size, radSeg, sides ) end
---Generate torus mesh
----- Failure return -1
----- Success return int
+---- Success return Mesh
---@param radius number
---@param size number
---@param radSeg integer
@@ -3155,55 +3109,40 @@ function RL.GenMeshTorus( radius, size, radSeg, sides ) end
function RL.GenMeshKnot( radius, size, radSeg, sides ) end
---Generate heightmap mesh from image data
----- Failure return -1
----- Success return int
+---- Success return Mesh
---@param heightmap any
---@param size table
---@return any mesh
function RL.GenMeshHeightmap( heightmap, size ) end
----Generate custom mesh from vertex attribute data and uploads it into a VAO ( if supported ) and VBO
----- Failure return -1
----- Success return int
----@param mesh any
+---Generate custom mesh from vertex attribute data and uploads it into a VAO (if supported) and VBO
+---- Success return Mesh
+---@param meshData any
---@param dynamic boolean
---@return any mesh
-function RL.GenMeshCustom( mesh, dynamic ) end
+function RL.GenMeshCustom( meshData, dynamic ) end
---Update mesh vertex data in GPU.
---Note! Mainly intented to be used with custom meshes.
----- Failure return false
----- Success return true
----@param mesh any
----@param updatedMesh any
----@return any success
-function RL.UpdateMesh( mesh, updatedMesh ) end
-
----Unload mesh data from CPU and GPU
----- Failure return false
----- Success return true
---@param mesh any
----@return any success
-function RL.UnloadMesh( mesh ) end
+---@param meshData any
+---@return any RL.UpdateMesh
+function RL.UpdateMesh( mesh, meshData ) end
---Draw a 3d mesh with material and transform
----- Failure return false
----- Success return true
---@param mesh any
---@param material any
---@param transform table
----@return any success
-function RL.DrawMesh( mesh, material, transform ) end
+---@return any RL.DrawMesh
+function RL.DrawMesh( mesh, material, transform ) end
---Draw multiple mesh instances with material and different transforms
----- Failure return false
----- Success return true
---@param mesh any
---@param material any
---@param transforms any
---@param instances integer
----@return any success
-function RL.DrawMeshInstanced( mesh, material, transforms, instances ) end
+---@return any RL.DrawMeshInstanced
+function RL.DrawMeshInstanced( mesh, material, transforms, instances ) end
---Updades mesh color vertex attribute buffer
---NOTE: Currently only works on custom mesh
@@ -3215,49 +3154,37 @@ function RL.DrawMeshInstanced( mesh, material, transforms, instances ) end
function RL.SetMeshColor( mesh, color ) end
---Export mesh data to file, returns true on success
----- Failure return false
----- Success return true
+---- Success return bool
---@param mesh any
---@param fileName string
---@return any success
function RL.ExportMesh( mesh, fileName ) end
---Compute mesh bounding box limits
----- Failure return false
---- Success return BoundingBox
---@param mesh any
---@return any boundingBox
function RL.GetMeshBoundingBox( mesh ) end
---Compute mesh tangents
----- Failure return false
----- Success return true
---@param mesh any
----@return any success
-function RL.GenMeshTangents( mesh ) end
+---@return any RL.GenMeshTangents
+function RL.GenMeshTangents( mesh ) end
-- Models - Material
---Load default material
----- Success return int
+---- Success return Material
---@return any material
function RL.LoadMaterialDefault() end
---Load material from table. See material table definition
----- Failure return false
----- Success return int
----@param material any
+---- Success return Material
+---@param materialData any
---@return any material
-function RL.CreateMaterial( material ) end
+function RL.CreateMaterial( materialData ) end
----Unload material from GPU memory ( VRAM )
----- Failure return false
----- Success return true
----@param material any
----@return any success
-function RL.UnloadMaterial( material ) end
-
----Set texture for a material map type ( MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS... )
+---Set texture for a material map type (MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS...)
---@param material any
---@param mapType integer
---@param texture any
@@ -3265,22 +3192,18 @@ function RL.UnloadMaterial( material ) end
function RL.SetMaterialTexture( material, mapType, texture ) end
---Set color for a material map type
----- Failure return false
----- Success return true
---@param material any
---@param mapType integer
---@param color table
----@return any success
-function RL.SetMaterialColor( material, mapType, color ) end
+---@return any RL.SetMaterialColor
+function RL.SetMaterialColor( material, mapType, color ) end
---Set value for a material map type
----- Failure return false
----- Success return true
---@param material any
---@param mapType integer
---@param value number
----@return any success
-function RL.SetMaterialValue( material, mapType, value ) end
+---@return any RL.SetMaterialValue
+function RL.SetMaterialValue( material, mapType, value ) end
---Set shader for material
---@param material any
@@ -3288,47 +3211,40 @@ function RL.SetMaterialValue( material, mapType, value ) end
---@return any RL.SetMaterialShader
function RL.SetMaterialShader( material, shader ) end
----Set material generic parameters ( if required )
----- Failure return false
----- Success return true
+---Set material generic parameters (if required)
---@param material any
---@param params any
----@return any success
-function RL.SetMaterialParams( material, params ) end
+---@return any RL.SetMaterialParams
+function RL.SetMaterialParams( material, params ) end
----Get texture from material map type. Returns -1 if no texture.
----- Failure return false
----- Success return int
+---Get texture from material map type. Returns -1 if no texture
+---- Success return Texture
---@param material any
---@param mapType integer
---@return any texture
function RL.GetMaterialTexture( material, mapType ) end
----Get color from material map type.
----- Failure return false
+---Get color from material map type
---- Success return Color
---@param material any
---@param mapType integer
---@return any color
function RL.GetMaterialColor( material, mapType ) end
----Get color from material map type.
----- Failure return false
+---Get color from material map type
---- Success return float
---@param material any
---@param mapType integer
---@return any value
function RL.GetMaterialValue( material, mapType ) end
----Get material shader. Returns -1 if no shader.
----- Failure return false
+---Get material shader
---- Success return Shader
---@param material any
---@return any shader
function RL.GetMaterialShader( material ) end
----Get material parameters.
----- Failure return false
+---Get material parameters
---- Success return float{}
---@param material any
---@return any params
@@ -3336,66 +3252,50 @@ function RL.GetMaterialParams( material ) end
-- Models - Model
----Load model from files ( Meshes and materials )
----- Failure return -1
----- Success return int
+---Load model from files (Meshes and materials)
+---- Failure return nil
+---- Success return Model
---@param fileName string
---@return any model
function RL.LoadModel( fileName ) end
----Load model from generated mesh ( Default material )
----- Failure return -1
----- Success return int
+---Load model from generated mesh (Default material)
+---- Success return Model
---@param mesh any
---@return any model
function RL.LoadModelFromMesh( mesh ) end
----Unload model ( Including meshes ) from memory ( RAM and/or VRAM )
----- Failure return false
----- Success return true
----@param model any
----@return any success
-function RL.UnloadModel( model ) end
-
----Draw a model ( With texture if set )
----- Failure return false
----- Success return true
+---Draw a model (With texture if set)
---@param model any
---@param position table
---@param scale number
---@param tint table
----@return any success
-function RL.DrawModel( model, position, scale, tint ) end
+---@return any RL.DrawModel
+function RL.DrawModel( model, position, scale, tint ) end
---Draw a model with extended parameters
----- Failure return false
----- Success return true
---@param model any
---@param position table
---@param rotationAxis table
---@param rotationAngle number
---@param scale table
---@param tint table
----@return any success
-function RL.DrawModelEx( model, position, rotationAxis, rotationAngle, scale, tint ) end
+---@return any RL.DrawModelEx
+function RL.DrawModelEx( model, position, rotationAxis, rotationAngle, scale, tint ) end
----Copies material to model material. ( Model material is the material id in models. Material can be deleted if not used elsewhere )
----- Failure return false
----- Success return true
+---Copies material to model material. (Model material is the material id in models.)
---@param model any
---@param modelMaterial any
---@param material any
----@return any success
-function RL.SetModelMaterial( model, modelMaterial, material ) end
+---@return any RL.SetModelMaterial
+function RL.SetModelMaterial( model, modelMaterial, material ) end
----Set material for a mesh ( Mesh and material on this model )
----- Failure return false
----- Success return true
+---Set material for a mesh (Mesh and material on this model)
---@param model any
---@param meshId integer
---@param materialId integer
----@return any success
-function RL.SetModelMeshMaterial( model, meshId, materialId ) end
+---@return any RL.SetModelMeshMaterial
+function RL.SetModelMeshMaterial( model, meshId, materialId ) end
---Draw a billboard texture
---@param camera any
@@ -3430,15 +3330,12 @@ function RL.DrawBillboardRec( camera, texture, source, position, size, tint ) e
function RL.DrawBillboardPro( camera, texture, source, position, up, size, origin, rotation, tint ) end
---Set model transform matrix
----- Failure return false
----- Success return true
---@param model any
---@param transform table
----@return any success
-function RL.SetModelTransform( model, transform ) end
+---@return any RL.SetModelTransform
+function RL.SetModelTransform( model, transform ) end
---Get model transform matrix
----- Failure return false
---- Success return Matrix
---@param model any
---@return any transform
@@ -3447,58 +3344,41 @@ function RL.GetModelTransform( model ) end
-- Model - Animations
---Load model animations from file
----- Failure return -1
----- Success return int, int
+---- Failure return nil
+---- Success return ModelAnimations{}
---@param fileName string
----@return any animations
----@return any animationCount
+---@return any animations
function RL.LoadModelAnimations( fileName ) end
---Update model animation pose
----- Failure return false
----- Success return true
---@param model any
----@param animations any
----@param animation integer
+---@param animation any
---@param frame integer
----@return any success
-function RL.UpdateModelAnimation( model, animations, animation, frame ) end
-
----Unload animation data
----- Failure return false
----- Success return true
----@param animations any
----@return any success
-function RL.UnloadModelAnimations( animations ) end
+---@return any RL.UpdateModelAnimation
+function RL.UpdateModelAnimation( model, animation, frame ) end
---Check model animation skeleton match
----- Failure return nil
---- Success return bool
---@param model any
----@param animations any
+---@param animation any
---@return any valid
-function RL.IsModelAnimationValid( model, animations ) end
+function RL.IsModelAnimationValid( model, animation ) end
---Return modelAnimation bone count
----- Failure return false
---- Success return int
----@param animations any
----@param animation integer
+---@param animation any
---@return any boneCount
-function RL.GetModelAnimationBoneCount( animations, animation ) end
+function RL.GetModelAnimationBoneCount( animation ) end
---Return modelAnimation frame count
----- Failure return false
---- Success return int
----@param animations any
----@param animation integer
+---@param animation any
---@return any frameCount
-function RL.GetModelAnimationFrameCount( animations, animation ) end
+function RL.GetModelAnimationFrameCount( animation ) end
-- Model - Collision
---Check collision between two spheres
----- Failure return nil
---- Success return bool
---@param center1 table
---@param radius1 number
@@ -3508,7 +3388,6 @@ function RL.GetModelAnimationFrameCount( animations, animation ) end
function RL.CheckCollisionSpheres( center1, radius1, center2, radius2 ) end
---Check collision between two bounding boxes
----- Failure return nil
---- Success return bool
---@param box1 any
---@param box2 any
@@ -3516,7 +3395,6 @@ function RL.CheckCollisionSpheres( center1, radius1, center2, radius2 ) end
function RL.CheckCollisionBoxes( box1, box2 ) end
---Check collision between box and sphere
----- Failure return nil
---- Success return bool
---@param box any
---@param center table
@@ -3525,7 +3403,6 @@ function RL.CheckCollisionBoxes( box1, box2 ) end
function RL.CheckCollisionBoxSphere( box, center, radius ) end
---Get collision info between ray and sphere. ( RayCollision is Lua table of { hit, distance, point, normal } )
----- Failure return nil
---- Success return RayCollision
---@param ray any
---@param center table
@@ -3534,7 +3411,6 @@ function RL.CheckCollisionBoxSphere( box, center, radius ) end
function RL.GetRayCollisionSphere( ray, center, radius ) end
---Get collision info between ray and box
----- Failure return nil
---- Success return RayCollision
---@param ray any
---@param box any
@@ -3542,7 +3418,6 @@ function RL.GetRayCollisionSphere( ray, center, radius ) end
function RL.GetRayCollisionBox( ray, box ) end
---Get collision info between ray and mesh
----- Failure return nil
---- Success return RayCollision
---@param ray any
---@param mesh any
@@ -3551,7 +3426,6 @@ function RL.GetRayCollisionBox( ray, box ) end
function RL.GetRayCollisionMesh( ray, mesh, transform ) end
---Get collision info between ray and triangle
----- Failure return nil
---- Success return RayCollision
---@param ray any
---@param p1 table
@@ -3561,7 +3435,6 @@ function RL.GetRayCollisionMesh( ray, mesh, transform ) end
function RL.GetRayCollisionTriangle( ray, p1, p2, p3 ) end
---Get collision info between ray and quad
----- Failure return nil
---- Success return RayCollision
---@param ray any
---@param p1 table
diff --git a/changelog b/changelog
index ab92cf0..deef58f 100644
--- a/changelog
+++ b/changelog
@@ -5,6 +5,7 @@ KEY CHANGES:
- CHANGED: Switch from ID based objects to userdata.
- CHANGED: Wrong arguments now largely crash the application instead of TraceLog state->logLevelInvalid.
- CHANGED: Rely mostly on luaL_check* functions for arg checking.
+ - CHANGED: ModelAnimations are changed to separate ModelAnimation types as in Raylib.
DETAILED CHANGES:
- CHANGED: GenImageColor now takes Vector2 as size.
@@ -17,6 +18,7 @@ DETAILED CHANGES:
- REMOVED: UnloadFont.
- ADDED: LoadFontEx takes also fontChars.
- REMOVED: UnloadWave and UnloadSound.
+ - REMOVED: UnloadMesh, UnloadMaterial, UnloadModel and UnloadModelAnimations.
------------------------------------------------------------------------
Release: ReiLua version 0.5.0 Using Raylib 4.5
diff --git a/examples/basic_lighting/main.lua b/examples/basic_lighting/main.lua
index d7e686a..d85291e 100644
--- a/examples/basic_lighting/main.lua
+++ b/examples/basic_lighting/main.lua
@@ -136,5 +136,5 @@ function RL.draw()
camera:endMode3D()
- RL.DrawText( 0, "Use keys [Y][R][G][B] to toggle lights", { 10, 10 }, 20, 4, RL.DARKGRAY )
+ RL.DrawText( RL.defaultFont, "Use keys [Y][R][G][B] to toggle lights", { 10, 10 }, 20, 4, RL.DARKGRAY )
end
diff --git a/examples/heightmap/main.lua b/examples/heightmap/main.lua
index 1b194bb..aa693fb 100644
--- a/examples/heightmap/main.lua
+++ b/examples/heightmap/main.lua
@@ -9,6 +9,7 @@ local TILE_SIZE = 32
local monitor = 0
local camera = {}
+local groundRenderTexture = -1
local groundTexture = -1
local tilesetTex = -1
local heigthImage = -1
@@ -47,10 +48,11 @@ function RL.init()
mesh = RL.GenMeshHeightmap( heigthImage, { 16, 4, 16 } )
tilesetTex = RL.LoadTexture( RL.GetBasePath().."../resources/images/tiles.png" )
- groundTexture = RL.LoadRenderTexture( { TILE_SIZE * 16, TILE_SIZE * 16 } )
+ groundRenderTexture = RL.LoadRenderTexture( { TILE_SIZE * 16, TILE_SIZE * 16 } )
+ groundTexture = RL.GetRenderTextureTexture( groundRenderTexture )
-- Draw to ground texture.
- RL.BeginTextureMode( groundTexture )
+ RL.BeginTextureMode( groundRenderTexture )
for x = 1, 16 do
for y = 1, 16 do
diff --git a/examples/iqm_test/main.lua b/examples/iqm_test/main.lua
index e5867a6..229c1c4 100644
--- a/examples/iqm_test/main.lua
+++ b/examples/iqm_test/main.lua
@@ -2,10 +2,10 @@
local monitor = 0
local camera = -1
+local texture = nil
local material = -1
local model = -1
-local animations = -1
-local animationCount = 0
+local animations = {}
local frame = 0
local curAnim = 0
local frameCount = 0
@@ -24,12 +24,14 @@ function RL.init()
RL.SetCamera3DTarget( camera, { 0, 0, 0 } )
RL.SetCamera3DUp( camera, { 0, 1, 0 } )
+ texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/monkey_tex.png" )
+
material = RL.CreateMaterial( {
maps = {
{
RL.MATERIAL_MAP_ALBEDO,
{
- texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/monkey_tex.png" ),
+ texture = texture,
color = RL.WHITE,
},
},
@@ -38,21 +40,19 @@ function RL.init()
model = RL.LoadModel( RL.GetBasePath().."../resources/iqm/monkey.iqm" )
RL.SetModelMaterial( model, 0, material )
- animations, animationCount = RL.LoadModelAnimations( RL.GetBasePath().."../resources/iqm/monkey.iqm" )
-
- print( "animationCount", animationCount )
+ animations = RL.LoadModelAnimations( RL.GetBasePath().."../resources/iqm/monkey.iqm" )
end
function RL.process( delta )
if RL.IsKeyPressed( RL.KEY_ENTER ) then
curAnim = curAnim + 1
- if animationCount <= curAnim then
+ if #animations <= curAnim then
curAnim = 0
end
frame = 0.0
- frameCount = RL.GetModelAnimationFrameCount( animations, curAnim )
+ frameCount = RL.GetModelAnimationFrameCount( animations[ curAnim + 1 ] )
elseif RL.IsKeyPressed( RL.KEY_UP ) then
animSpeed = animSpeed + 5
elseif RL.IsKeyPressed( RL.KEY_DOWN ) then
@@ -60,7 +60,7 @@ function RL.process( delta )
end
if RL.IsKeyDown( RL.KEY_SPACE ) then
- RL.UpdateModelAnimation( model, animations, curAnim, math.floor( frame ) )
+ RL.UpdateModelAnimation( model, animations[ curAnim + 1 ], math.floor( frame ) )
frame = frame + animSpeed * delta
if frameCount < frame then
@@ -80,7 +80,7 @@ function RL.draw()
RL.DrawModelEx( model, { 0, 0, 0 }, { 1.0, 0.0, 0.0 }, -90.0, { 1.0, 1.0, 1.0 }, RL.WHITE )
RL.EndMode3D()
- RL.DrawText( 0,
+ RL.DrawText( RL.defaultFont,
"Enter: Change animation\
Space: Play animation\
Up arrow: Inreace animation speed\
diff --git a/examples/lightmap/main.lua b/examples/lightmap/main.lua
index 11cd632..6d946a5 100644
--- a/examples/lightmap/main.lua
+++ b/examples/lightmap/main.lua
@@ -55,6 +55,8 @@ function RL.init()
shader = RL.LoadShader( RL.GetBasePath().."../resources/shaders/glsl330/lightmap.vs",
RL.GetBasePath().."../resources/shaders/glsl330/lightmap.fs" )
+ print( "shader", shader )
+
local materialData = {
shader = shader,
maps = {
@@ -77,6 +79,9 @@ function RL.init()
},
}
material = RL.CreateMaterial( materialData )
+
+ print( "material", material )
+
matrix = RL.MatrixMultiply( RL.MatrixIdentity(), RL.MatrixTranslate( { -4, 0, -4 } ) )
end
@@ -102,3 +107,10 @@ function RL.draw()
RL.DrawMesh( mesh, material, matrix )
camera:endMode3D()
end
+
+function RL.exit()
+ material = nil
+ collectgarbage( "collect" )
+ tileTexture = nil
+ collectgarbage( "collect" )
+end \ No newline at end of file
diff --git a/examples/window/main.lua b/examples/window/main.lua
index 2b4a009..ed0227b 100644
--- a/examples/window/main.lua
+++ b/examples/window/main.lua
@@ -32,5 +32,5 @@ end
function RL.draw()
RL.ClearBackground( RL.RAYWHITE )
RL.DrawTexture( texture, { 20, 20 }, RL.WHITE )
- RL.DrawText( RL.fontDefault, text, textPos, 20, 2, textColor )
+ RL.DrawText( RL.defaultFont, text, textPos, 20, 2, textColor )
end
diff --git a/include/lua_core.h b/include/lua_core.h
index 2996b54..861b235 100644
--- a/include/lua_core.h
+++ b/include/lua_core.h
@@ -79,6 +79,10 @@ void uluaPushWave( lua_State *L, Wave wave );
void uluaPushSound( lua_State *L, Sound sound );
void uluaPushMusic( lua_State *L, Music music );
void uluaPushLight( lua_State *L, Light light );
+void uluaPushMaterial( lua_State *L, Material material );
+void uluaPushMesh( lua_State *L, Mesh mesh );
+void uluaPushModel( lua_State *L, Model model );
+void uluaPushModelAnimation( lua_State *L, ModelAnimation modelAnimation );
int uluaGetTableLen( lua_State *L );
int uluaGetTableLenIndex( lua_State *L, int index );
diff --git a/include/models.h b/include/models.h
index 5d9ea23..ba92732 100644
--- a/include/models.h
+++ b/include/models.h
@@ -38,7 +38,6 @@ int lmodelsGenMeshKnot( lua_State *L );
int lmodelsGenMeshHeightmap( lua_State *L );
int lmodelsGenMeshCustom( lua_State *L );
int lmodelsUpdateMesh( lua_State *L );
-int lmodelsUnloadMesh( lua_State *L );
int lmodelsDrawMesh( lua_State *L );
int lmodelsDrawMeshInstanced( lua_State *L );
int lmodelsSetMeshColor( lua_State *L );
@@ -48,7 +47,6 @@ int lmodelsGenMeshTangents( 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 );
@@ -62,7 +60,6 @@ int lmodelsGetMaterialParams( 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 );
@@ -75,7 +72,6 @@ int lmodelsGetModelTransform( lua_State *L );
/* Animations. */
int lmodelsLoadModelAnimations( lua_State *L );
int lmodelsUpdateModelAnimation( lua_State *L );
-int lmodelsUnloadModelAnimations( lua_State *L );
int lmodelsIsModelAnimationValid( lua_State *L );
int lmodelsGetModelAnimationBoneCount( lua_State *L );
int lmodelsGetModelAnimationFrameCount( lua_State *L );
diff --git a/include/state.h b/include/state.h
index 37a6d8c..4b023aa 100644
--- a/include/state.h
+++ b/include/state.h
@@ -3,34 +3,12 @@
#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 logLevelInvalid;
- /* Resources. */
- /* 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;
/* Raylib GLFW input callback events. */
/* Window events. */
GLFWwindowsizefun raylibWindowSizeCallback;
diff --git a/src/lua_core.c b/src/lua_core.c
index 9641fdf..fa60517 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -194,7 +194,7 @@ static void defineMusic() {
lua_setfield( L, -2, "__gc" );
}
-/* Music. */
+/* Light. */
static void defineLight() {
lua_State *L = state->luaState;
@@ -203,6 +203,93 @@ static void defineLight() {
lua_setfield( L, -2, "__index" );
}
+/* Material. */
+static int gcMaterial( lua_State *L ) {
+ Material *material = luaL_checkudata ( L, 1, "Material" );
+ printf( "gcMaterial\n" );
+
+ // int MAX_MATERIAL_MAPS = 12;
+
+
+ // Unload loaded texture maps (avoid unloading default texture, managed by raylib)
+ // if ( material->maps != NULL ) {
+ // for ( int i = 0; i < MAX_MATERIAL_MAPS; i++ ) {
+ // if ( material->maps[i].texture.id != rlGetTextureIdDefault() ) {
+ // printf( "gcMaterial material->maps[i].texture.id = %d\n", material->maps[i].texture.id );
+ // rlUnloadTexture( material->maps[i].texture.id );
+ // }
+ // }
+ // }
+
+ /* Custom UnloadMaterial since we don't want to free Shaders or Textures. */
+ RL_FREE( material->maps );
+}
+
+static void defineMaterial() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Material" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcMaterial );
+ lua_setfield( L, -2, "__gc" );
+}
+
+/* Mesh. */
+static int gcMesh( lua_State *L ) {
+ Mesh *mesh = luaL_checkudata ( L, 1, "Mesh" );
+ printf( "gcMesh\n" );
+
+ UnloadMesh( *mesh );
+}
+
+static void defineMesh() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Mesh" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcMesh );
+ lua_setfield( L, -2, "__gc" );
+}
+
+/* Model. */
+static int gcModel( lua_State *L ) {
+ Model *model = luaL_checkudata ( L, 1, "Model" );
+ printf( "gcModel\n" );
+
+ UnloadModel( *model );
+ // UnloadModelKeepMeshes( *model );
+}
+
+static void defineModel() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Model" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcModel );
+ lua_setfield( L, -2, "__gc" );
+}
+
+/* ModelAnimation. */
+static int gcModelAnimation( lua_State *L ) {
+ ModelAnimation *modelAnimation = luaL_checkudata ( L, 1, "ModelAnimation" );
+ printf( "gcModelAnimation\n" );
+
+ UnloadModelAnimation( *modelAnimation );
+}
+
+static void defineModelAnimation() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "ModelAnimation" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcModelAnimation );
+ lua_setfield( L, -2, "__gc" );
+}
+
/* Assing globals. */
static void assignGlobalInt( int value, const char *name ) {
@@ -243,7 +330,10 @@ static void defineGlobals() {
lua_getglobal( L, "RL" );
uluaPushFont( L, GetFontDefault() );
- lua_setfield( L, -2, "fontDefault" );
+ lua_setfield( L, -2, "defaultFont" );
+
+ uluaPushMaterial( L, LoadMaterialDefault() );
+ lua_setfield( L, -2, "defaultMaterial" );
/*DOC_START*/
/* ConfigFlags */
@@ -1229,6 +1319,10 @@ bool luaInit( int argn, const char **argc ) {
defineSound();
defineMusic();
defineLight();
+ defineMaterial();
+ defineMesh();
+ defineModel();
+ defineModelAnimation();
/* Define globals. */
defineGlobals();
@@ -1769,7 +1863,6 @@ void luaRegister() {
assingGlobalFunction( "GenMeshHeightmap", lmodelsGenMeshHeightmap );
assingGlobalFunction( "GenMeshCustom", lmodelsGenMeshCustom );
assingGlobalFunction( "UpdateMesh", lmodelsUpdateMesh );
- assingGlobalFunction( "UnloadMesh", lmodelsUnloadMesh );
assingGlobalFunction( "DrawMesh", lmodelsDrawMesh );
assingGlobalFunction( "DrawMeshInstanced", lmodelsDrawMeshInstanced );
assingGlobalFunction( "SetMeshColor", lmodelsSetMeshColor );
@@ -1779,7 +1872,6 @@ void luaRegister() {
/* Material. */
assingGlobalFunction( "LoadMaterialDefault", lmodelsLoadMaterialDefault );
assingGlobalFunction( "CreateMaterial", lmodelsCreateMaterial );
- assingGlobalFunction( "UnloadMaterial", lmodelsUnloadMaterial );
assingGlobalFunction( "SetMaterialTexture", lmodelsSetMaterialTexture );
assingGlobalFunction( "SetMaterialColor", lmodelsSetMaterialColor );
assingGlobalFunction( "SetMaterialValue", lmodelsSetMaterialValue );
@@ -1793,7 +1885,6 @@ void luaRegister() {
/* Model. */
assingGlobalFunction( "LoadModel", lmodelsLoadModel );
assingGlobalFunction( "LoadModelFromMesh", lmodelsLoadModelFromMesh );
- assingGlobalFunction( "UnloadModel", lmodelsUnloadModel );
assingGlobalFunction( "DrawModel", lmodelsDrawModel );
assingGlobalFunction( "DrawModelEx", lmodelsDrawModelEx );
assingGlobalFunction( "SetModelMaterial", lmodelsSetModelMaterial );
@@ -1806,7 +1897,6 @@ void luaRegister() {
/* Animations. */
assingGlobalFunction( "LoadModelAnimations", lmodelsLoadModelAnimations );
assingGlobalFunction( "UpdateModelAnimation", lmodelsUpdateModelAnimation );
- assingGlobalFunction( "UnloadModelAnimations", lmodelsUnloadModelAnimations );
assingGlobalFunction( "IsModelAnimationValid", lmodelsIsModelAnimationValid );
assingGlobalFunction( "GetModelAnimationBoneCount", lmodelsGetModelAnimationBoneCount );
assingGlobalFunction( "GetModelAnimationFrameCount", lmodelsGetModelAnimationFrameCount );
@@ -2988,6 +3078,30 @@ void uluaPushLight( lua_State *L, Light light ) {
luaL_setmetatable( L, "Light" );
}
+void uluaPushMaterial( lua_State *L, Material material ) {
+ Material *materialP = lua_newuserdata( L, sizeof( Material ) );
+ *materialP = material;
+ luaL_setmetatable( L, "Material" );
+}
+
+void uluaPushMesh( lua_State *L, Mesh mesh ) {
+ Mesh *meshP = lua_newuserdata( L, sizeof( Mesh ) );
+ *meshP = mesh;
+ luaL_setmetatable( L, "Mesh" );
+}
+
+void uluaPushModel( lua_State *L, Model model ) {
+ Model *modelP = lua_newuserdata( L, sizeof( Model ) );
+ *modelP = model;
+ luaL_setmetatable( L, "Model" );
+}
+
+void uluaPushModelAnimation( lua_State *L, ModelAnimation modelAnimation ) {
+ ModelAnimation *modelAnimationP = lua_newuserdata( L, sizeof( ModelAnimation ) );
+ *modelAnimationP = modelAnimation;
+ luaL_setmetatable( L, "ModelAnimation" );
+}
+
int uluaGetTableLen( lua_State *L ) {
return uluaGetTableLenIndex( L, lua_gettop( L ) );
}
diff --git a/src/models.c b/src/models.c
index 77e900c..9889fa1 100644
--- a/src/models.c
+++ b/src/models.c
@@ -6,162 +6,6 @@
#include "textures.h"
#include "core.h"
-static void checkMeshRealloc( int i ) {
- if ( i == state->meshCount ) {
- state->meshCount++;
- }
-
- if ( state->meshCount == state->meshAlloc ) {
- state->meshAlloc += ALLOC_PAGE_SIZE;
- state->meshes = realloc( state->meshes, state->meshAlloc * sizeof( Mesh* ) );
-
- for ( i = state->meshCount; i < state->meshAlloc; i++ ) {
- state->meshes[i] = NULL;
- }
- }
-}
-
-static void checkMaterialRealloc( int i ) {
- if ( i == state->materialCount ) {
- state->materialCount++;
- }
-
- if ( state->materialCount == state->materialAlloc ) {
- state->materialAlloc += ALLOC_PAGE_SIZE;
- state->materials = realloc( state->materials, state->materialAlloc * sizeof( Material* ) );
-
- for ( i = state->materialCount; i < state->materialAlloc; i++ ) {
- state->materials[i] = NULL;
- }
- }
-}
-
-static void checkModelRealloc( int i ) {
- if ( i == state->modelCount ) {
- state->modelCount++;
- }
-
- if ( state->modelCount == state->modelAlloc ) {
- state->modelAlloc += ALLOC_PAGE_SIZE;
- state->models = realloc( state->models, state->modelAlloc * sizeof( Model* ) );
-
- for ( i = state->modelCount; i < state->modelAlloc; i++ ) {
- state->models[i] = NULL;
- }
- }
-}
-
-static void checkAnimationRealloc( int i ) {
- if ( i == state->animationCount ) {
- state->animationCount++;
- }
-
- if ( state->animationCount == state->animationAlloc ) {
- state->animationAlloc += ALLOC_PAGE_SIZE;
- state->animations = realloc( state->animations, state->animationAlloc * sizeof( ModelAnimations* ) );
-
- for ( i = state->animationCount; i < state->animationAlloc; i++ ) {
- state->animations[i] = NULL;
- }
- }
-}
-
-static bool validMesh( size_t id ) {
- if ( id < 0 || state->meshCount < id || state->meshes[ id ] == NULL ) {
- TraceLog( state->logLevelInvalid, "%s %d", "Invalid mesh", id );
- return false;
- }
- else {
- return true;
- }
-}
-
-static bool validMaterial( size_t id ) {
- if ( id < 0 || state->materialCount < id || state->materials[ id ] == NULL ) {
- TraceLog( state->logLevelInvalid, "%s %d", "Invalid material", id );
- return false;
- }
- else {
- return true;
- }
-}
-
-static bool validModel( size_t id ) {
- if ( id < 0 || state->modelCount < id || state->models[ id ] == NULL ) {
- TraceLog( state->logLevelInvalid, "%s %d", "Invalid model", id );
- return false;
- }
- else {
- return true;
- }
-}
-
-static bool validAnimation( size_t id ) {
- if ( id < 0 || state->animationCount < id || state->animations[ id ] == NULL ) {
- TraceLog( state->logLevelInvalid, "%s %d", "Invalid animation", id );
- return false;
- }
- else {
- return true;
- }
-}
-
-static int newMesh() {
- int i = 0;
-
- for ( i = 0; i < state->meshCount; i++ ) {
- if ( state->meshes[i] == NULL ) {
- break;
- }
- }
- state->meshes[i] = malloc( sizeof( Mesh ) );
- checkMeshRealloc( i );
-
- return i;
-}
-
-static int newMaterial() {
- int i = 0;
-
- for ( i = 0; i < state->materialCount; i++ ) {
- if ( state->materials[i] == NULL ) {
- break;
- }
- }
- state->materials[i] = malloc( sizeof( Material ) );
- checkMaterialRealloc( i );
-
- return i;
-}
-
-static int newModel() {
- int i = 0;
-
- for ( i = 0; i < state->modelCount; i++ ) {
- if ( state->models[i] == NULL ) {
- break;
- }
- }
- state->models[i] = malloc( sizeof( Model ) );
- checkModelRealloc( i );
-
- return i;
-}
-
-static int newAnimation() {
- int i = 0;
-
- for ( i = 0; i < state->animationCount; i++ ) {
- if ( state->animations[i] == NULL ) {
- break;
- }
- }
- state->animations[i] = malloc( sizeof( ModelAnimations ) );
- checkAnimationRealloc( i );
-
- return i;
-}
-
// Unload model (but not meshes) from memory (RAM and/or VRAM)
void UnloadModelKeepMeshes( Model model ) {
// Unload materials maps
@@ -283,426 +127,273 @@ void DrawBillboardRecNoRatio( Camera camera, Texture2D texture, Rectangle source
*/
/*
-> success = RL.DrawLine3D( Vector3 startPos, Vector3 endPos, Color color )
+> RL.DrawLine3D( Vector3 startPos, Vector3 endPos, Color color )
Draw a line in 3D world space
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawLine3D( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawLine3D( Vector3 startPos, Vector3 endPos, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 startPos = uluaGetVector3Index( L, 1 );
Vector3 endPos = uluaGetVector3Index( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
DrawLine3D( startPos, endPos, color);
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawPoint3D( Vector3 position, Color color )
+> RL.DrawPoint3D( Vector3 position, Color color )
Draw a point in 3D space, actually a small line
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawPoint3D( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawPoint3D( Vector3 position, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 position = uluaGetVector3Index( L, 1 );
Color color = uluaGetColorIndex( L, 2 );
DrawPoint3D( position, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawCircle3D( Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color )
+> RL.DrawCircle3D( Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color )
Draw a circle in 3D world space
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawCircle3D( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCircle3D( Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 center = uluaGetVector3Index( L, 1 );
- float radius = lua_tonumber( L, 2 );
+ float radius = luaL_checknumber( L, 2 );
Vector3 rotationAxis = uluaGetVector3Index( L, 3 );
- float rotationAngle = lua_tonumber( L, 4 );
+ float rotationAngle = luaL_checknumber( L, 4 );
Color color = uluaGetColorIndex( L, 5 );
DrawCircle3D( center, radius, rotationAxis, rotationAngle, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawTriangle3D( Vector3 v1, Vector3 v2, Vector3 v3, Color color )
-
-Draw a color-filled triangle ( Vertex in counter-clockwise order! )
+> RL.DrawTriangle3D( Vector3 v1, Vector3 v2, Vector3 v3, Color color )
-- Failure return false
-- Success return true
+Draw a color-filled triangle (Vertex in counter-clockwise order!)
*/
int lmodelsDrawTriangle3D( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawTriangle3D( Vector3 v1, Vector3 v2, Vector3 v3, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 v1 = uluaGetVector3Index( L, 1 );
Vector3 v2 = uluaGetVector3Index( L, 2 );
Vector3 v3 = uluaGetVector3Index( L, 3 );
Color color = uluaGetColorIndex( L, 4 );
DrawTriangle3D( v1, v2, v3, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawCube( Vector3 position, Vector3 size, Color color )
+> RL.DrawCube( Vector3 position, Vector3 size, Color color )
Draw cube
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawCube( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCube( Vector3 position, Vector3 size, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 pos = uluaGetVector3Index( L, 1 );
Vector3 size = uluaGetVector3Index( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
DrawCubeV( pos, size, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawCubeWires( Vector3 position, Vector3 size, Color color )
+> RL.DrawCubeWires( Vector3 position, Vector3 size, Color color )
Draw cube wires
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawCubeWires( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCubeWires( Vector3 position, Vector3 size, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 pos = uluaGetVector3Index( L, 1 );
Vector3 size = uluaGetVector3Index( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
DrawCubeWiresV( pos, size, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawSphere( Vector3 centerPos, float radius, Color color )
+> RL.DrawSphere( Vector3 centerPos, float radius, Color color )
Draw sphere
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawSphere( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawSphere( Vector3 centerPos, float radius, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 centerPos = uluaGetVector3Index( L, 1 );
- float radius = lua_tonumber( L, 2 );
+ float radius = luaL_checknumber( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
DrawSphere( centerPos, radius, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawSphereEx( Vector3 centerPos, float radius, int rings, int slices, Color color )
+> RL.DrawSphereEx( Vector3 centerPos, float radius, int rings, int slices, Color color )
Draw sphere with extended parameters
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawSphereEx( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawSphereEx( Vector3 centerPos, float radius, int rings, int slices, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 centerPos = uluaGetVector3Index( L, 1 );
- float radius = lua_tonumber( L, 2 );
- int rings = lua_tointeger( L, 3 );
- int slices = lua_tointeger( L, 4 );
+ float radius = luaL_checknumber( L, 2 );
+ int rings = luaL_checkinteger( L, 3 );
+ int slices = luaL_checkinteger( L, 4 );
Color color = uluaGetColorIndex( L, 5 );
DrawSphereEx( centerPos, radius, rings, slices, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawSphereWires( Vector3 centerPos, float radius, int rings, int slices, Color color )
+> RL.DrawSphereWires( Vector3 centerPos, float radius, int rings, int slices, Color color )
Draw sphere wires
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawSphereWires( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawSphereWires( Vector3 centerPos, float radius, int rings, int slices, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 centerPos = uluaGetVector3Index( L, 1 );
- float radius = lua_tonumber( L, 2 );
- int rings = lua_tointeger( L, 3 );
- int slices = lua_tointeger( L, 4 );
+ float radius = luaL_checknumber( L, 2 );
+ int rings = luaL_checkinteger( L, 3 );
+ int slices = luaL_checkinteger( L, 4 );
Color color = uluaGetColorIndex( L, 5 );
DrawSphereWires( centerPos, radius, rings, slices, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawCylinder( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )
+> RL.DrawCylinder( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )
Draw a cylinder/cone
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawCylinder( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCylinder( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 position = uluaGetVector3Index( L, 1 );
- float radiusTop = lua_tonumber( L, 2 );
- float radiusBottom = lua_tonumber( L, 3 );
- float height = lua_tonumber( L, 4 );
- int slices = lua_tointeger( L, 5 );
+ float radiusTop = luaL_checknumber( L, 2 );
+ float radiusBottom = luaL_checknumber( L, 3 );
+ float height = luaL_checknumber( L, 4 );
+ int slices = luaL_checkinteger( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
DrawCylinder( position, radiusTop, radiusBottom, height, slices, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawCylinderEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )
+> RL.DrawCylinderEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )
Draw a cylinder with base at startPos and top at endPos
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawCylinderEx( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCylinderEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 startPos = uluaGetVector3Index( L, 1 );
Vector3 endPos = uluaGetVector3Index( L, 2 );
- float startRadius = lua_tonumber( L, 3 );
- float endRadius = lua_tonumber( L, 4 );
- int sides = lua_tointeger( L, 5 );
+ float startRadius = luaL_checknumber( L, 3 );
+ float endRadius = luaL_checknumber( L, 4 );
+ int sides = luaL_checkinteger( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
DrawCylinderEx( startPos, endPos, startRadius, endRadius, sides, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawCylinderWires( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )
+> RL.DrawCylinderWires( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )
Draw a cylinder/cone wires
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawCylinderWires( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCylinderWires( Vector3 position, float radiusTop, float radiusBottom, float height, int slices, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 position = uluaGetVector3Index( L, 1 );
- float radiusTop = lua_tonumber( L, 2 );
- float radiusBottom = lua_tonumber( L, 3 );
- float height = lua_tonumber( L, 4 );
- int slices = lua_tointeger( L, 5 );
+ float radiusTop = luaL_checknumber( L, 2 );
+ float radiusBottom = luaL_checknumber( L, 3 );
+ float height = luaL_checknumber( L, 4 );
+ int slices = luaL_checkinteger( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
DrawCylinderWires( position, radiusTop, radiusBottom, height, slices, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawCylinderWiresEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )
+> RL.DrawCylinderWiresEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )
Draw a cylinder wires with base at startPos and top at endPos
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawCylinderWiresEx( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCylinderWiresEx( Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 startPos = uluaGetVector3Index( L, 1 );
Vector3 endPos = uluaGetVector3Index( L, 2 );
- float startRadius = lua_tonumber( L, 3 );
- float endRadius = lua_tonumber( L, 4 );
- int sides = lua_tointeger( L, 5 );
+ float startRadius = luaL_checknumber( L, 3 );
+ float endRadius = luaL_checknumber( L, 4 );
+ int sides = luaL_checkinteger( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
DrawCylinderWiresEx( startPos, endPos, startRadius, endRadius, sides, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
+> RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
Draw a capsule with the center of its sphere caps at startPos and endPos
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawCapsule( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 startPos = uluaGetVector3Index( L, 1 );
Vector3 endPos = uluaGetVector3Index( L, 2 );
- float radius = lua_tonumber( L, 3 );
- int slices = lua_tonumber( L, 4 );
- int rings = lua_tointeger( L, 5 );
+ float radius = luaL_checknumber( L, 3 );
+ int slices = luaL_checkinteger( L, 4 );
+ int rings = luaL_checkinteger( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
DrawCapsule( startPos, endPos, radius, slices, rings, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
+> RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )
Draw capsule wireframe with the center of its sphere caps at startPos and endPos
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawCapsuleWires( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 startPos = uluaGetVector3Index( L, 1 );
Vector3 endPos = uluaGetVector3Index( L, 2 );
- float radius = lua_tonumber( L, 3 );
- int slices = lua_tonumber( L, 4 );
- int rings = lua_tointeger( L, 5 );
+ float radius = luaL_checknumber( L, 3 );
+ int slices = luaL_checkinteger( L, 4 );
+ int rings = luaL_checkinteger( L, 5 );
Color color = uluaGetColorIndex( L, 6 );
DrawCapsuleWires( startPos, endPos, radius, slices, rings, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawPlane( Vector3 centerPos, Vector2 size, Color color )
+> RL.DrawPlane( Vector3 centerPos, Vector2 size, Color color )
Draw a plane XZ
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawPlane( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawPlane( Vector3 centerPos, Vector2 size, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector3 centerPos = uluaGetVector3Index( L, 1 );
Vector2 size = uluaGetVector2Index( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
DrawPlane( centerPos, size, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
> RL.DrawQuad3DTexture( Texture texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )
-Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ).
+Draw 3D textured quad. (Texture coordinates opengl style 0.0 - 1.0).
*/
int lmodelDrawQuad3DTexture( lua_State *L ) {
Texture *texture = luaL_checkudata( L, 1, "Texture" );
@@ -768,49 +459,31 @@ int lmodelDrawQuad3DTexture( lua_State *L ) {
}
/*
-> success = RL.DrawRay( Ray ray, Color color )
+> RL.DrawRay( Ray ray, Color color )
Draw a ray line
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawRay( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawRay( Ray ray, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
Ray ray = uluaGetRayIndex( L, 1 );
Color color = uluaGetColorIndex( L, 2 );
DrawRay( ray, color );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawGrid( int slices, float spacing )
+> RL.DrawGrid( int slices, float spacing )
-Draw a grid ( Centered at ( 0, 0, 0 ) )
-
-- Failure return false
-- Success return true
+Draw a grid (Centered at ( 0, 0, 0 ))
*/
int lmodelsDrawGrid( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawGrid( int slices, float spacing )" );
- lua_pushboolean( L, false );
- return 1;
- }
- int slices = lua_tointeger( L, 1 );
- float spacing = lua_tonumber( L, 2 );
+ int slices = luaL_checkinteger( L, 1 );
+ float spacing = luaL_checknumber( L, 2 );
DrawGrid( slices, spacing );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
@@ -822,23 +495,13 @@ int lmodelsDrawGrid( lua_State *L ) {
Generate polygonal mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshPoly( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshPoly( int sides, float radius )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- int sides = lua_tointeger( L, 1 );
- float radius = lua_tonumber( L, 2 );
-
- int i = newMesh();
+ int sides = luaL_checkinteger( L, 1 );
+ float radius = luaL_checknumber( L, 2 );
- *state->meshes[i] = GenMeshPoly( sides, radius );
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, GenMeshPoly( sides, radius ) );
return 1;
}
@@ -846,27 +509,17 @@ int lmodelsGenMeshPoly( lua_State *L ) {
/*
> mesh = RL.GenMeshPlane( float width, float length, int resX, int resZ )
-Generate plane mesh ( With subdivisions )
+Generate plane mesh (With subdivisions)
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshPlane( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshPlane( float width, float length, int resX, int resZ )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- float width = lua_tonumber( L, 1 );
- float length = lua_tonumber( L, 2 );
- int resX = lua_tointeger( L, 3 );
- int resZ = lua_tointeger( L, 4 );
-
- int i = newMesh();
+ float width = luaL_checknumber( L, 1 );
+ float length = luaL_checknumber( L, 2 );
+ int resX = luaL_checkinteger( L, 3 );
+ int resZ = luaL_checkinteger( L, 4 );
- *state->meshes[i] = GenMeshPlane( width, length, resX, resZ );
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, GenMeshPlane( width, length, resX, resZ ) );
return 1;
}
@@ -876,22 +529,12 @@ int lmodelsGenMeshPlane( lua_State *L ) {
Generate cuboid mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshCube( lua_State *L ) {
- if ( !lua_istable( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshCube( Vector3 size )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
Vector3 size = uluaGetVector3Index( L, 1 );
- int i = newMesh();
-
- *state->meshes[i] = GenMeshCube( size.x, size.y, size.z );
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, GenMeshCube( size.x, size.y, size.z ) );
return 1;
}
@@ -899,26 +542,16 @@ int lmodelsGenMeshCube( lua_State *L ) {
/*
> mesh = RL.GenMeshSphere( float radius, int rings, int slices )
-Generate sphere mesh ( Standard sphere )
+Generate sphere mesh (Standard sphere)
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshSphere( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshSphere( float radius, int rings, int slices )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- float radius = lua_tonumber( L, 1 );
- int rings = lua_tointeger( L, 2 );
- int slices = lua_tointeger( L, 3 );
-
- int i = newMesh();
+ float radius = luaL_checknumber( L, 1 );
+ int rings = luaL_checkinteger( L, 2 );
+ int slices = luaL_checkinteger( L, 3 );
- *state->meshes[i] = GenMeshSphere( radius, rings, slices );
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, GenMeshSphere( radius, rings, slices ) );
return 1;
}
@@ -928,24 +561,14 @@ int lmodelsGenMeshSphere( lua_State *L ) {
Generate cylinder mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshCylinder( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshCylinder( float radius, float height, int slices )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- float radius = lua_tonumber( L, 1 );
- float height = lua_tonumber( L, 2 );
- int slices = lua_tointeger( L, 3 );
+ float radius = luaL_checknumber( L, 1 );
+ float height = luaL_checknumber( L, 2 );
+ int slices = luaL_checkinteger( L, 3 );
- int i = newMesh();
-
- *state->meshes[i] = GenMeshCylinder( radius, height, slices);
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, GenMeshCylinder( radius, height, slices ) );
return 1;
}
@@ -955,24 +578,14 @@ int lmodelsGenMeshCylinder( lua_State *L ) {
Generate cone/pyramid mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshCone( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshCone( float radius, float height, int slices )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- float radius = lua_tonumber( L, 1 );
- float height = lua_tonumber( L, 2 );
- int slices = lua_tointeger( L, 3 );
+ float radius = luaL_checknumber( L, 1 );
+ float height = luaL_checknumber( L, 2 );
+ int slices = luaL_checkinteger( L, 3 );
- int i = newMesh();
-
- *state->meshes[i] = GenMeshCone( radius, height, slices);
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, GenMeshCone( radius, height, slices ) );
return 1;
}
@@ -982,25 +595,15 @@ int lmodelsGenMeshCone( lua_State *L ) {
Generate torus mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshTorus( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshTorus( float radius, float size, int radSeg, int sides )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- float radius = lua_tonumber( L, 1 );
- float size = lua_tonumber( L, 2 );
- int radSeg = lua_tointeger( L, 3 );
- int sides = lua_tointeger( L, 4 );
+ float radius = luaL_checknumber( L, 1 );
+ float size = luaL_checknumber( L, 2 );
+ int radSeg = luaL_checkinteger( L, 3 );
+ int sides = luaL_checkinteger( L, 4 );
- int i = newMesh();
-
- *state->meshes[i] = GenMeshTorus( radius, size, radSeg, sides );
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, GenMeshTorus( radius, size, radSeg, sides ) );
return 1;
}
@@ -1010,25 +613,15 @@ int lmodelsGenMeshTorus( lua_State *L ) {
Generate torus mesh
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshKnot( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshKnot( float radius, float size, int radSeg, int sides )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- float radius = lua_tonumber( L, 1 );
- float size = lua_tonumber( L, 2 );
- int radSeg = lua_tointeger( L, 3 );
- int sides = lua_tointeger( L, 4 );
+ float radius = luaL_checknumber( L, 1 );
+ float size = luaL_checknumber( L, 2 );
+ int radSeg = luaL_checkinteger( L, 3 );
+ int sides = luaL_checkinteger( L, 4 );
- int i = newMesh();
-
- *state->meshes[i] = GenMeshKnot( radius, size, radSeg, sides );
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, GenMeshKnot( radius, size, radSeg, sides ) );
return 1;
}
@@ -1038,36 +631,28 @@ int lmodelsGenMeshKnot( lua_State *L ) {
Generate heightmap mesh from image data
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshHeightmap( lua_State *L ) {
Image *heightmap = luaL_checkudata( L, 1, "Image" );
Vector3 size = uluaGetVector3Index( L, 2 );
- int i = newMesh();
-
- *state->meshes[i] = GenMeshHeightmap( *heightmap, size );
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, GenMeshHeightmap( *heightmap, size ) );
return 1;
}
/*
-> mesh = RL.GenMeshCustom( Mesh{} mesh, bool dynamic )
+> mesh = RL.GenMeshCustom( Mesh{} meshData, bool dynamic )
-Generate custom mesh from vertex attribute data and uploads it into a VAO ( if supported ) and VBO
+Generate custom mesh from vertex attribute data and uploads it into a VAO (if supported) and VBO
-- Failure return -1
-- Success return int
+- Success return Mesh
*/
int lmodelsGenMeshCustom( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isboolean( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshCustom( Mesh{} mesh, bool dynamic )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
+ luaL_checktype( L, 1, LUA_TTABLE );
+ bool dynamic = uluaGetBoolean( L, 2 );
+
Mesh mesh = { 0 };
int t = 1;
@@ -1207,41 +792,21 @@ int lmodelsGenMeshCustom( lua_State *L ) {
}
lua_pop( L, 1 );
}
- bool dynamic = lua_toboolean( L, 2 );
-
UploadMesh( &mesh, dynamic );
-
- int i = newMesh();
-
- *state->meshes[i] = mesh;
- lua_pushinteger( L, i );
- checkMeshRealloc( i );
+ uluaPushMesh( L, mesh );
return 1;
}
/*
-> success = RL.UpdateMesh( Mesh mesh, Mesh{} updatedMesh )
+> RL.UpdateMesh( Mesh mesh, Mesh{} meshData )
Update mesh vertex data in GPU.
Note! Mainly intented to be used with custom meshes.
-
-- Failure return false
-- Success return true
*/
int lmodelsUpdateMesh( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateMesh( Mesh mesh, Mesh{} updatedMesh )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t meshId = lua_tointeger( L, 1 );
-
- if ( !validMesh( meshId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- Mesh *mesh = state->meshes[ meshId ];
+ Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
+ luaL_checktype( L, 2, LUA_TTABLE );
int t = 2;
lua_pushnil( L );
@@ -1354,84 +919,35 @@ int lmodelsUpdateMesh( lua_State *L ) {
}
lua_pop( L, 1 );
}
- lua_pushboolean( L, true );
-
- return 1;
-}
-
-/*
-> success = RL.UnloadMesh( Mesh mesh )
-
-Unload mesh data from CPU and GPU
-
-- Failure return false
-- Success return true
-*/
-int lmodelsUnloadMesh( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadMesh( Mesh mesh )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t id = lua_tointeger( L, 1 );
-
- if ( !validMesh( id ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- UnloadMesh( *state->meshes[ id ] );
- state->meshes[ id ] = NULL;
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawMesh( Mesh mesh, Material material, Matrix transform )
+> RL.DrawMesh( Mesh mesh, Material material, Matrix transform )
Draw a 3d mesh with material and transform
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawMesh( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawMesh( Mesh mesh, Material material, Matrix transform )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t meshId = lua_tointeger( L, 1 );
- size_t materialId = lua_tointeger( L, 2 );
+ Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
+ Material *material = luaL_checkudata( L, 2, "Material" );
Matrix matrix = uluaGetMatrixIndex( L, 3 );
- if ( !validMesh( meshId ) || !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
- DrawMesh( *state->meshes[ meshId ], *state->materials[ materialId ], matrix );
- lua_pushboolean( L, true );
+ DrawMesh( *mesh, *material, matrix );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawMeshInstanced( Mesh mesh, Material material, Matrix{} transforms, int instances )
+> RL.DrawMeshInstanced( Mesh mesh, Material material, Matrix{} transforms, int instances )
Draw multiple mesh instances with material and different transforms
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawMeshInstanced( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) || !lua_isnumber( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawMeshInstanced( Mesh mesh, Material material, Matrix{} transforms, int instances )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t meshId = lua_tointeger( L, 1 );
- size_t materialId = lua_tointeger( L, 2 );
- int instances = lua_tointeger( L, 4 );
+ Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
+ Material *material = luaL_checkudata( L, 2, "Material" );
+ luaL_checktype( L, 3, LUA_TTABLE );
+ int instances = luaL_checkinteger( L, 4 );
Matrix transforms[ instances ];
@@ -1445,15 +961,9 @@ int lmodelsDrawMeshInstanced( lua_State *L ) {
i++;
lua_pop( L, 1 );
}
+ DrawMeshInstanced( *mesh, *material, transforms, instances );
- if ( !validMesh( meshId ) || !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- DrawMeshInstanced( *state->meshes[ meshId ], *state->materials[ materialId ], transforms, instances );
- lua_pushboolean( L, true );
-
- return 1;
+ return 0;
}
/*
@@ -1466,23 +976,11 @@ NOTE: Currently only works on custom mesh
- Success return true
*/
int lmodelsSetMeshColor( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMeshColor( Mesh mesh, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t meshId = lua_tointeger( L, 1 );
+ Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
Color color = uluaGetColorIndex( L, 2 );
- if ( !validMesh( meshId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
- Mesh *mesh = state->meshes[ meshId ];
-
if ( mesh->colors == NULL ) {
- TraceLog( state->logLevelInvalid, "Mesh %d %s", meshId, "Mesh doesn't have vertex colors allocated" );
+ TraceLog( state->logLevelInvalid, "Mesh doesn't have vertex colors allocated" );
lua_pushboolean( L, false );
return 1;
}
@@ -1506,22 +1004,12 @@ int lmodelsSetMeshColor( lua_State *L ) {
Export mesh data to file, returns true on success
-- Failure return false
-- Success return true
+- Success return bool
*/
int lmodelsExportMesh( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ExportMesh( Mesh mesh, string fileName )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t meshId = lua_tointeger( L, 1 );
+ Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
- if ( !validMesh( meshId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushboolean( L, ExportMesh( *state->meshes[ meshId ], lua_tostring( L, 2 ) ) );
+ lua_pushboolean( L, ExportMesh( *mesh, luaL_checkstring( L, 2 ) ) );
return 1;
}
@@ -1531,50 +1019,27 @@ int lmodelsExportMesh( lua_State *L ) {
Compute mesh bounding box limits
-- Failure return false
- Success return BoundingBox
*/
int lmodelsGetMeshBoundingBox( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMeshBoundingBox( Mesh mesh )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t meshId = lua_tointeger( L, 1 );
+ Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
- if ( !validMesh( meshId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushBoundingBox( L, GetMeshBoundingBox( *state->meshes[ meshId ] ) );
+ uluaPushBoundingBox( L, GetMeshBoundingBox( *mesh ) );
return 1;
}
/*
-> success = RL.GenMeshTangents( Mesh mesh )
+> RL.GenMeshTangents( Mesh mesh )
Compute mesh tangents
-
-- Failure return false
-- Success return true
*/
int lmodelsGenMeshTangents( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshTangents( Mesh mesh )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t meshId = lua_tointeger( L, 1 );
+ Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
- if ( !validMesh( meshId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- GenMeshTangents( state->meshes[ meshId ] );
- lua_pushboolean( L, true );
+ GenMeshTangents( mesh );
- return 1;
+ return 0;
}
/*
@@ -1586,34 +1051,25 @@ int lmodelsGenMeshTangents( lua_State *L ) {
Load default material
-- Success return int
+- Success return Material
*/
int lmodelsLoadMaterialDefault( lua_State *L ) {
- int i = newMaterial();
-
- *state->materials[i] = LoadMaterialDefault();
- lua_pushinteger( L, i );
+ uluaPushMaterial( L, LoadMaterialDefault() );
return 1;
}
/*
-> material = RL.CreateMaterial( Material{} material )
+> material = RL.CreateMaterial( Material{} materialData )
Load material from table. See material table definition
-- Failure return false
-- Success return int
+- Success return Material
*/
int lmodelsCreateMaterial( lua_State *L ) {
- if ( !lua_istable( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CreateMaterial( Material{} material )" );
- lua_pushboolean( L, false );
- return 1;
- }
- int i = newMaterial();
+ luaL_checktype( L, 1, LUA_TTABLE );
- *state->materials[i] = LoadMaterialDefault();
+ Material material = LoadMaterialDefault();
int t = lua_gettop( L );
lua_pushnil( L );
@@ -1642,13 +1098,14 @@ int lmodelsCreateMaterial( lua_State *L ) {
while ( lua_next( L, t4 ) != 0 ) {
if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
Texture *texture = luaL_checkudata( L, lua_gettop( L ), "Texture" );
- state->materials[i]->maps[map].texture = *texture;
+ material.maps[map].texture = *texture;
+ printf( "Material Create material.maps[map].texture.id = %d\n", material.maps[map].texture.id );
}
else if ( strcmp( "color", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- state->materials[i]->maps[map].color = uluaGetColorIndex( L, lua_gettop( L ) );
+ material.maps[map].color = uluaGetColorIndex( L, lua_gettop( L ) );
}
else if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- state->materials[i]->maps[map].value = luaL_checkinteger( L, -1 );
+ material.maps[map].value = luaL_checkinteger( L, -1 );
}
lua_pop( L, 1 );
}
@@ -1664,53 +1121,25 @@ int lmodelsCreateMaterial( lua_State *L ) {
lua_pop( L, 1 );
}
}
- else if ( strcmp( "params", (char*)lua_tostring( L, -2 ) ) == 0 && lua_istable( L, -1 ) ) {
+ else if ( strcmp( "params", (char*)lua_tostring( L, -2 ) ) == 0 ) {
int t2 = lua_gettop( L ), j = 0;
lua_pushnil( L );
while ( lua_next( L, t2 ) != 0 ) {
if ( j <= 3 ) {
- state->materials[i]->params[j] = lua_tonumber( L, -1 );
+ material.params[j] = luaL_checknumber( L, -1 );
}
j++;
lua_pop( L, 1 );
}
}
- else if ( strcmp( "shader", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
+ else if ( strcmp( "shader", (char*)lua_tostring( L, -2 ) ) == 0 ) {
Shader *shader = luaL_checkudata( L, lua_gettop( L ), "Shader" );
- state->materials[i]->shader = *shader;
+ material.shader = *shader;
}
lua_pop( L, 1 );
}
- lua_pushinteger( L, i );
- checkMaterialRealloc( i );
-
- return 1;
-}
-
-/*
-> success = RL.UnloadMaterial( Material material )
-
-Unload material from GPU memory ( VRAM )
-
-- Failure return false
-- Success return true
-*/
-int lmodelsUnloadMaterial( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadMaterial( Material material )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t id = lua_tointeger( L, 1 );
-
- if ( !validMaterial( id ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- UnloadMaterial( *state->materials[ id ] );
- state->materials[ id ] = NULL;
- lua_pushboolean( L, true );
+ uluaPushMaterial( L, material );
return 1;
}
@@ -1718,72 +1147,46 @@ int lmodelsUnloadMaterial( lua_State *L ) {
/*
> RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )
-Set texture for a material map type ( MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS... )
+Set texture for a material map type (MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS...)
*/
int lmodelsSetMaterialTexture( lua_State *L ) {
- size_t materialId = lua_tointeger( L, 1 );
- int mapType = lua_tointeger( L, 2 );
+ Material *material = luaL_checkudata( L, 1, "Material" );
+ int mapType = luaL_checkinteger( L, 2 );
Texture *texture = luaL_checkudata( L, 3, "Texture" );
- SetMaterialTexture( state->materials[ materialId ], mapType, *texture );
+ SetMaterialTexture( material, mapType, *texture );
return 0;
}
/*
-> success = RL.SetMaterialColor( Material material, int mapType, Color color )
+> RL.SetMaterialColor( Material material, int mapType, Color color )
Set color for a material map type
-
-- Failure return false
-- Success return true
*/
int lmodelsSetMaterialColor( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMaterialColor( Material material, int mapType, Color color )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t materialId = lua_tointeger( L, 1 );
- size_t mapType = lua_tointeger( L, 2 );
+ Material *material = luaL_checkudata( L, 1, "Material" );
+ int mapType = luaL_checkinteger( L, 2 );
Color color = uluaGetColorIndex( L, 3 );
- if ( !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- state->materials[ materialId ]->maps[ mapType ].color = color;
- lua_pushboolean( L, true );
+ material->maps[ mapType ].color = color;
- return 1;
+ return 0;
}
/*
-> success = RL.SetMaterialValue( Material material, int mapType, float value )
+> RL.SetMaterialValue( Material material, int mapType, float value )
Set value for a material map type
-
-- Failure return false
-- Success return true
*/
int lmodelsSetMaterialValue( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMaterialValue( Material material, int mapType, float value )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t materialId = lua_tointeger( L, 1 );
- size_t mapType = lua_tointeger( L, 2 );
- float value = lua_tonumber( L, 3 );
+ Material *material = luaL_checkudata( L, 1, "Material" );
+ int mapType = luaL_checkinteger( L, 2 );
+ float value = luaL_checknumber( L, 3 );
- if ( !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- state->materials[ materialId ]->maps[ mapType ].value = value;
- lua_pushboolean( L, true );
+ material->maps[ mapType ].value = value;
- return 1;
+ return 0;
}
/*
@@ -1792,35 +1195,24 @@ int lmodelsSetMaterialValue( lua_State *L ) {
Set shader for material
*/
int lmodelsSetMaterialShader( lua_State *L ) {
- size_t materialId = lua_tointeger( L, 1 );
+ Material *material = luaL_checkudata( L, 1, "Material" );
Shader *shader = luaL_checkudata( L, 2, "Shader" );
- state->materials[ materialId ]->shader = *shader;
+ material->shader = *shader;
return 0;
}
/*
-> success = RL.SetMaterialParams( Material material, float{} params )
-
-Set material generic parameters ( if required )
+> RL.SetMaterialParams( Material material, float{} params )
-- Failure return false
-- Success return true
+Set material generic parameters (if required)
*/
int lmodelsSetMaterialParams( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMaterialParams( Material material, float{} params )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t len = uluaGetTableLen( L );
- size_t materialId = lua_tointeger( L, 1 );
+ Material *material = luaL_checkudata( L, 1, "Material" );
+
+ size_t len = uluaGetTableLenIndex( L, 2 );
- if ( !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
float params[ len ];
int t = lua_gettop( L );
@@ -1835,48 +1227,24 @@ int lmodelsSetMaterialParams( lua_State *L ) {
int paramCount = ( len > 4 ) ? 4 : len;
for ( int i = 0; i < paramCount; i++ ) {
- state->materials[ materialId ]->params[i] = params[i];
+ material->params[i] = params[i];
}
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
> texture = RL.GetMaterialTexture( Material material, int mapType )
-Get texture from material map type. Returns -1 if no texture.
+Get texture from material map type. Returns -1 if no texture
-- Failure return false
-- Success return int
+- Success return Texture
*/
int lmodelsGetMaterialTexture( lua_State *L ) {
- // if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- // TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialTexture( Material material, int mapType )" );
- // lua_pushboolean( L, false );
- // return 1;
- // }
- // size_t materialId = lua_tointeger( L, 1 );
- // int mapType = lua_tointeger( L, 2 );
-
- // if ( !validMaterial( materialId ) ) {
- // lua_pushboolean( L, false );
- // return 1;
- // }
- // /* Check what ReiLua texture has same openGL texture and return that. */
- // for ( int i = 0; i < state->textureCount; i++ ) {
- // if ( state->textures[i]->type == TEXTURE_TYPE_TEXTURE
- // && state->textures[i]->texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
- // lua_pushinteger( L, i );
- // return 1;
- // }
- // else if ( state->textures[i]->type == TEXTURE_TYPE_RENDER_TEXTURE
- // && state->textures[i]->renderTexture.texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
- // lua_pushinteger( L, i );
- // return 1;
- // }
- // }
- // lua_pushinteger( L, -1 );
+ Material *material = luaL_checkudata( L, 1, "Material" );
+ int mapType = luaL_checkinteger( L, 2 );
+
+ uluaPushTexture( L, material->maps[ mapType ].texture );
return 1;
}
@@ -1884,25 +1252,15 @@ int lmodelsGetMaterialTexture( lua_State *L ) {
/*
> color = RL.GetMaterialColor( Material material, int mapType )
-Get color from material map type.
+Get color from material map type
-- Failure return false
- Success return Color
*/
int lmodelsGetMaterialColor( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialColor( Material material, int mapType )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t materialId = lua_tointeger( L, 1 );
- int mapType = lua_tointeger( L, 2 );
+ Material *material = luaL_checkudata( L, 1, "Material" );
+ int mapType = luaL_checkinteger( L, 2 );
- if ( !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushColor( L, state->materials[ materialId ]->maps[ mapType ].color );
+ uluaPushColor( L, material->maps[ mapType ].color );
return 1;
}
@@ -1910,25 +1268,15 @@ int lmodelsGetMaterialColor( lua_State *L ) {
/*
> value = RL.GetMaterialValue( Material material, int mapType )
-Get color from material map type.
+Get color from material map type
-- Failure return false
- Success return float
*/
int lmodelsGetMaterialValue( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialValue( Material material, int mapType )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t materialId = lua_tointeger( L, 1 );
- int mapType = lua_tointeger( L, 2 );
+ Material *material = luaL_checkudata( L, 1, "Material" );
+ int mapType = luaL_checkinteger( L, 2 );
- if ( !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushnumber( L, state->materials[ materialId ]->maps[ mapType ].value );
+ lua_pushnumber( L, material->maps[ mapType ].value );
return 1;
}
@@ -1936,34 +1284,14 @@ int lmodelsGetMaterialValue( lua_State *L ) {
/*
> shader = RL.GetMaterialShader( Material material )
-Get material shader. Returns -1 if no shader.
+Get material shader
-- Failure return false
- Success return Shader
*/
int lmodelsGetMaterialShader( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialShader( Material material )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t materialId = lua_tointeger( L, 1 );
-
- if ( !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
+ Material *material = luaL_checkudata( L, 1, "Material" );
- uluaPushShader( L, state->materials[ materialId ]->shader );
-
- /* Look for shader that has same shader program id. */
- // for ( int i = 0; i < state->shaderCount; i++ ) {
- // if ( state->shaders[i]->id == state->materials[ materialId ]->shader.id ) {
- // lua_pushinteger( L, i );
- // return 1;
- // }
- // }
- // lua_pushinteger( L, -1 );
+ uluaPushShader( L, material->shader );
return 1;
}
@@ -1971,28 +1299,18 @@ int lmodelsGetMaterialShader( lua_State *L ) {
/*
> params = RL.GetMaterialParams( Material material )
-Get material parameters.
+Get material parameters
-- Failure return false
- Success return float{}
*/
int lmodelsGetMaterialParams( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialParams( Material material )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t materialId = lua_tointeger( L, 1 );
+ Material *material = luaL_checkudata( L, 1, "Material" );
- if ( !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
Vector4 params = {
- state->materials[ materialId ]->params[0],
- state->materials[ materialId ]->params[1],
- state->materials[ materialId ]->params[2],
- state->materials[ materialId ]->params[3]
+ material->params[0],
+ material->params[1],
+ material->params[2],
+ material->params[3]
};
uluaPushVector4( L, params );
@@ -2006,28 +1324,19 @@ int lmodelsGetMaterialParams( lua_State *L ) {
/*
> model = RL.LoadModel( string fileName )
-Load model from files ( Meshes and materials )
+Load model from files (Meshes and materials)
-- Failure return -1
-- Success return int
+- Failure return nil
+- Success return Model
*/
int lmodelsLoadModel( lua_State *L ) {
- if ( !lua_isstring( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadModel( string fileName )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
+ if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
+ uluaPushModel( L, LoadModel( lua_tostring( L, 1 ) ) );
- if ( FileExists( lua_tostring( L, 1 ) ) ) {
- int i = newModel();
- *state->models[i] = LoadModel( lua_tostring( L, 1 ) );
- lua_pushinteger( L, i );
- return 1;
- }
- else {
- lua_pushinteger( L, -1 );
return 1;
}
+ TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) );
+ lua_pushnil( L );
return 1;
}
@@ -2035,144 +1344,61 @@ int lmodelsLoadModel( lua_State *L ) {
/*
> model = RL.LoadModelFromMesh( Mesh mesh )
-Load model from generated mesh ( Default material )
+Load model from generated mesh (Default material)
-- Failure return -1
-- Success return int
+- Success return Model
*/
int lmodelsLoadModelFromMesh( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadModelFromMesh( Mesh mesh )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- size_t meshId = lua_tointeger( L, 1 );
-
- if ( !validMesh( meshId ) ) {
- lua_pushinteger( L, -1 );
- return 1;
- }
- int i = newModel();
-
- *state->models[i] = LoadModelFromMesh( *state->meshes[ meshId ] );
- lua_pushinteger( L, i );
-
- return 1;
-}
-
-/*
-> success = RL.UnloadModel( Model model )
-
-Unload model ( Including meshes ) from memory ( RAM and/or VRAM )
-
-- Failure return false
-- Success return true
-*/
-int lmodelsUnloadModel( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadModel( Model model )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelId = lua_tointeger( L, 1 );
+ Mesh *mesh = luaL_checkudata( L, 1, "Mesh" );
- if ( !validModel( modelId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- UnloadModel( *state->models[ modelId ] );
- state->models[ modelId ] = NULL;
- lua_pushboolean( L, true );
+ uluaPushModel( L, LoadModelFromMesh( *mesh ) );
return 1;
}
/*
-> success = RL.DrawModel( Model model, Vector3 position, float scale, Color tint )
+> RL.DrawModel( Model model, Vector3 position, float scale, Color tint )
-Draw a model ( With texture if set )
-
-- Failure return false
-- Success return true
+Draw a model (With texture if set)
*/
int lmodelsDrawModel( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawModel( Model model, Vector3 position, float scale, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelId = lua_tointeger( L, 1 );
+ Model *model = luaL_checkudata( L, 1, "Model" );
Vector3 position = uluaGetVector3Index( L, 2 );
- float scale = lua_tonumber( L, 3 );
+ float scale = luaL_checknumber( L, 3 );
Color tint = uluaGetColorIndex( L, 4 );
- if ( !validModel( modelId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
-
- DrawModel( *state->models[ modelId ], position, scale, tint );
- lua_pushboolean( L, true );
+ DrawModel( *model, position, scale, tint );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawModelEx( Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint )
+> RL.DrawModelEx( Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint )
Draw a model with extended parameters
-
-- Failure return false
-- Success return true
*/
int lmodelsDrawModelEx( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawModelEx( Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelId = lua_tointeger( L, 1 );
+ Model *model = luaL_checkudata( L, 1, "Model" );
Vector3 position = uluaGetVector3Index( L, 2 );
Vector3 rotationAxis = uluaGetVector3Index( L, 3 );
- float rotationAngle = lua_tonumber( L, 4 );
+ float rotationAngle = luaL_checknumber( L, 4 );
Vector3 scale = uluaGetVector3Index( L, 5 );
Color tint = uluaGetColorIndex( L, 6 );
- if ( !validModel( modelId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- DrawModelEx( *state->models[ modelId ], position, rotationAxis, rotationAngle, scale, tint );
- lua_pushboolean( L, true );
+ DrawModelEx( *model, position, rotationAxis, rotationAngle, scale, tint );
- return 1;
+ return 0;
}
/*
-> success = RL.SetModelMaterial( Model model, Material modelMaterial, Material material )
+> RL.SetModelMaterial( Model model, Material modelMaterial, Material material )
-Copies material to model material. ( Model material is the material id in models. Material can be deleted if not used elsewhere )
-
-- Failure return false
-- Success return true
+Copies material to model material. (Model material is the material id in models.)
*/
int lmodelsSetModelMaterial( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetModelMaterial( Model model, Material modelMaterial, Material material )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelId = lua_tointeger( L, 1 );
- int modelMaterialId = lua_tointeger( L, 2 );
- size_t materialId = lua_tointeger( L, 3 );
-
- if ( !validModel( modelId ) || !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- Model *model = state->models[ modelId ];
- Material *material = state->materials[ materialId ];
+ Model *model = luaL_checkudata( L, 1, "Model" );
+ int modelMaterialId = luaL_checkinteger( L, 2 );
+ Material *material = luaL_checkudata( L, 3, "Material" );
/* Copy material data instead of using pointer. Pointer would result in double free error. */
model->materials[ modelMaterialId ].shader = material->shader;
@@ -2191,37 +1417,23 @@ int lmodelsSetModelMaterial( lua_State *L ) {
for ( int i = 0; i < 4; i++ ) {
model->materials[ modelMaterialId ].params[i] = material->params[i];
}
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.SetModelMeshMaterial( Model model, int meshId, int materialId )
-
-Set material for a mesh ( Mesh and material on this model )
+> RL.SetModelMeshMaterial( Model model, int meshId, int materialId )
-- Failure return false
-- Success return true
+Set material for a mesh (Mesh and material on this model)
*/
int lmodelsSetModelMeshMaterial( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetModelMeshMaterial( Model model, int meshId, int materialId )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelId = lua_tointeger( L, 1 );
- size_t meshId = lua_tointeger( L, 2 );
- size_t materialId = lua_tointeger( L, 3 );
+ Model *model = luaL_checkudata( L, 1, "Model" );
+ int meshId = luaL_checkinteger( L, 2 );
+ int materialId = luaL_checkinteger( L, 3 );
- if ( !validModel( modelId ) || !validMesh( meshId ) || !validMaterial( materialId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- SetModelMeshMaterial( state->models[ modelId ], meshId, materialId );
- lua_pushboolean( L, true );
+ SetModelMeshMaterial( model, meshId, materialId );
- return 1;
+ return 0;
}
/*
@@ -2281,30 +1493,17 @@ int lmodelsDrawBillboardPro( lua_State *L ) {
}
/*
-> success = RL.SetModelTransform( Model model, Matrix transform )
+> RL.SetModelTransform( Model model, Matrix transform )
Set model transform matrix
-
-- Failure return false
-- Success return true
*/
int lmodelsSetModelTransform( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetModelTransform( Model model, Matrix transform )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelId = lua_tointeger( L, 1 );
+ Model *model = luaL_checkudata( L, 1, "Model" );
Matrix transform = uluaGetMatrixIndex( L, 2 );
- if ( !validModel( modelId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- state->models[ modelId ]->transform = transform;
- lua_pushboolean( L, true );
+ model->transform = transform;
- return 1;
+ return 0;
}
/*
@@ -2312,22 +1511,12 @@ int lmodelsSetModelTransform( lua_State *L ) {
Get model transform matrix
-- Failure return false
- Success return Matrix
*/
int lmodelsGetModelTransform( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetModelTransform( Model model )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelId = lua_tointeger( L, 1 );
+ Model *model = luaL_checkudata( L, 1, "Model" );
- if ( !validModel( modelId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushMatrix( L, state->models[ modelId ]->transform );
+ uluaPushMatrix( L, model->transform );
return 1;
}
@@ -2337,166 +1526,90 @@ int lmodelsGetModelTransform( lua_State *L ) {
*/
/*
-> animations, animationCount = RL.LoadModelAnimations( string fileName )
+> animations = RL.LoadModelAnimations( string fileName )
Load model animations from file
-- Failure return -1
-- Success return int, int
+- Failure return nil
+- Success return ModelAnimations{}
*/
int lmodelsLoadModelAnimations( lua_State *L ) {
- if ( !lua_isstring( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadModelAnimations( string fileName )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
+ if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
+ int animationCount = 0;
+ ModelAnimation *anims = LoadModelAnimations( lua_tostring( L, 1 ), &animationCount );
- if ( FileExists( lua_tostring( L, 1 ) ) ) {
- int i = newAnimation();
- state->animations[i]->animations = LoadModelAnimations( lua_tostring( L, 1 ), &state->animations[i]->animCount );
- lua_pushinteger( L, i );
- lua_pushinteger( L, state->animations[i]->animCount );
+ lua_createtable( L, animationCount, 0 );
- return 2;
- }
- else {
- lua_pushinteger( L, -1 );
- return 1;
- }
-}
-
-/*
-> success = RL.UpdateModelAnimation( Model model, ModelAnimations animations, int animation, int frame )
-
-Update model animation pose
-
-- Failure return false
-- Success return true
-*/
-int lmodelsUpdateModelAnimation( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateModelAnimation( Model model, ModelAnimations animations, int animation, int frame )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelId = lua_tointeger( L, 1 );
- size_t modelAnimId = lua_tointeger( L, 2 );
- size_t animId = lua_tointeger( L, 3 );
- int frame = imax( 0, lua_tointeger( L, 4 ) );
+ for ( int i = 0; i < animationCount; i++ ) {
+ uluaPushModelAnimation( L, anims[i] );
+ lua_rawseti( L, -2, i+1 );
+ }
- if ( !validModel( modelId ) || !validAnimation( modelAnimId ) ) {
- lua_pushboolean( L, false );
return 1;
}
- UpdateModelAnimation( *state->models[ modelId ], state->animations[ modelAnimId ]->animations[ animId ], frame );
- lua_pushboolean( L, true );
+ TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) );
+ lua_pushnil( L );
return 1;
}
/*
-> success = RL.UnloadModelAnimations( ModelAnimations animations )
+> RL.UpdateModelAnimation( Model model, ModelAnimation animation, int frame )
-Unload animation data
-
-- Failure return false
-- Success return true
+Update model animation pose
*/
-int lmodelsUnloadModelAnimations( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadModelAnimations( ModelAnimations animations )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelAnimId = lua_tointeger( L, 1 );
-
- if ( !validAnimation( modelAnimId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- UnloadModelAnimation( *state->animations[ modelAnimId ]->animations );
- state->animations[ modelAnimId ]->animCount = 0;
- state->animations[ modelAnimId ] = NULL;
+int lmodelsUpdateModelAnimation( lua_State *L ) {
+ Model *model = luaL_checkudata( L, 1, "Model" );
+ ModelAnimation *modelAnimation = luaL_checkudata( L, 2, "ModelAnimation" );
+ int frame = luaL_checkinteger( L, 3 );
- lua_pushboolean( L, true );
+ UpdateModelAnimation( *model, *modelAnimation, frame );
- return 1;
+ return 0;
}
/*
-> valid = RL.IsModelAnimationValid( Model model, ModelAnimations animations )
+> valid = RL.IsModelAnimationValid( Model model, ModelAnimation animation )
Check model animation skeleton match
-- Failure return nil
- Success return bool
*/
int lmodelsIsModelAnimationValid( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.IsModelAnimationValid( Model model, ModelAnimations animations )" );
- lua_pushnil( L );
- return 1;
- }
- size_t modelId = lua_tointeger( L, 1 );
- size_t modelAnimId = lua_tointeger( L, 2 );
+ Model *model = luaL_checkudata( L, 1, "Model" );
+ ModelAnimation *modelAnimation = luaL_checkudata( L, 2, "ModelAnimation" );
- if ( !validModel( modelId ) || !validAnimation( modelAnimId ) ) {
- lua_pushnil( L );
- return 1;
- }
- lua_pushboolean( L, IsModelAnimationValid( *state->models[ modelId ], *state->animations[ modelAnimId ]->animations ) );
+ lua_pushboolean( L, IsModelAnimationValid( *model, *modelAnimation ) );
return 1;
}
/*
-> boneCount = RL.GetModelAnimationBoneCount( ModelAnimations animations, int animation )
+> boneCount = RL.GetModelAnimationBoneCount( ModelAnimation animation )
Return modelAnimation bone count
-- Failure return false
- Success return int
*/
int lmodelsGetModelAnimationBoneCount( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetModelAnimationBoneCount( ModelAnimations animations, int animation )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelAnimId = lua_tointeger( L, 1 );
- int animId = lua_tointeger( L, 2 );
+ ModelAnimation *modelAnimation = luaL_checkudata( L, 1, "ModelAnimation" );
- if ( !validAnimation( modelAnimId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushinteger( L, state->animations[ modelAnimId ]->animations[ animId ].boneCount );
+ lua_pushinteger( L, modelAnimation->boneCount );
return 1;
}
/*
-> frameCount = RL.GetModelAnimationFrameCount( ModelAnimations animations, int animation )
+> frameCount = RL.GetModelAnimationFrameCount( ModelAnimation animation )
Return modelAnimation frame count
-- Failure return false
- Success return int
*/
int lmodelsGetModelAnimationFrameCount( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetModelAnimationFrameCount( ModelAnimations animations, int animation )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t modelAnimId = lua_tointeger( L, 1 );
- int animId = lua_tointeger( L, 2 );
+ ModelAnimation *modelAnimation = luaL_checkudata( L, 1, "ModelAnimation" );
- if ( !validAnimation( modelAnimId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushinteger( L, state->animations[ modelAnimId ]->animations[ animId ].frameCount );
+ lua_pushinteger( L, modelAnimation->frameCount );
return 1;
}
@@ -2510,19 +1623,13 @@ int lmodelsGetModelAnimationFrameCount( lua_State *L ) {
Check collision between two spheres
-- Failure return nil
- Success return bool
*/
int lmodelsCheckCollisionSpheres( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) || !lua_isnumber( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CheckCollisionSpheres( Vector3 center1, float radius1, Vector3 center2, float radius2 )" );
- lua_pushnil( L );
- return 1;
- }
Vector3 center1 = uluaGetVector3Index( L, 1 );
- float radius1 = lua_tonumber( L, 2 );
+ float radius1 = luaL_checknumber( L, 2 );
Vector3 center2 = uluaGetVector3Index( L, 3 );
- float radius2 = lua_tonumber( L, 4 );
+ float radius2 = luaL_checknumber( L, 4 );
lua_pushboolean( L, CheckCollisionSpheres( center1, radius1, center2, radius2 ) );
@@ -2534,15 +1641,9 @@ int lmodelsCheckCollisionSpheres( lua_State *L ) {
Check collision between two bounding boxes
-- Failure return nil
- Success return bool
*/
int lmodelsCheckCollisionBoxes( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CheckCollisionBoxes( BoundingBox box1, BoundingBox box2 )" );
- lua_pushnil( L );
- return 1;
- }
BoundingBox box1 = uluaGetBoundingBoxIndex( L, 1 );
BoundingBox box2 = uluaGetBoundingBoxIndex( L, 2 );
@@ -2556,18 +1657,12 @@ int lmodelsCheckCollisionBoxes( lua_State *L ) {
Check collision between box and sphere
-- Failure return nil
- Success return bool
*/
int lmodelsCheckCollisionBoxSphere( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CheckCollisionBoxSphere( BoundingBox box, Vector3 center, float radius )" );
- lua_pushnil( L );
- return 1;
- }
BoundingBox box = uluaGetBoundingBoxIndex( L, 1 );
Vector3 center = uluaGetVector3Index( L, 2 );
- float radius = lua_tonumber( L, 3 );
+ float radius = luaL_checknumber( L, 3 );
lua_pushboolean( L, CheckCollisionBoxSphere( box, center, radius ) );
@@ -2579,18 +1674,12 @@ int lmodelsCheckCollisionBoxSphere( lua_State *L ) {
Get collision info between ray and sphere. ( RayCollision is Lua table of { hit, distance, point, normal } )
-- Failure return nil
- Success return RayCollision
*/
int lmodelsGetRayCollisionSphere( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetRayCollisionSphere( Ray ray, Vector3 center, float radius )" );
- lua_pushnil( L );
- return 1;
- }
Ray ray = uluaGetRayIndex( L, 1 );
Vector3 center = uluaGetVector3Index( L, 2 );
- float radius = lua_tonumber( L, 3 );
+ float radius = luaL_checknumber( L, 3 );
uluaPushRayCollision( L, GetRayCollisionSphere( ray, center, radius ) );
@@ -2602,15 +1691,9 @@ int lmodelsGetRayCollisionSphere( lua_State *L ) {
Get collision info between ray and box
-- Failure return nil
- Success return RayCollision
*/
int lmodelsGetRayCollisionBox( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetRayCollisionBox( Ray ray, BoundingBox box )" );
- lua_pushnil( L );
- return 1;
- }
Ray ray = uluaGetRayIndex( L, 1 );
BoundingBox box = uluaGetBoundingBoxIndex( L, 2 );
@@ -2624,24 +1707,14 @@ int lmodelsGetRayCollisionBox( lua_State *L ) {
Get collision info between ray and mesh
-- Failure return nil
- Success return RayCollision
*/
int lmodelsGetRayCollisionMesh( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_istable( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetRayCollisionMesh( Ray ray, Mesh mesh, Matrix transform )" );
- lua_pushnil( L );
- return 1;
- }
Ray ray = uluaGetRayIndex( L, 1 );
- size_t meshId = lua_tointeger( L, 2 );
+ Mesh *mesh = luaL_checkudata( L, 2, "Mesh" );
Matrix transform = uluaGetMatrixIndex( L, 3 );
- if ( !validMesh( meshId ) ) {
- lua_pushnil( L );
- return 1;
- }
- uluaPushRayCollision( L, GetRayCollisionMesh( ray, *state->meshes[ meshId ], transform ) );
+ uluaPushRayCollision( L, GetRayCollisionMesh( ray, *mesh, transform ) );
return 1;
}
@@ -2651,15 +1724,9 @@ int lmodelsGetRayCollisionMesh( lua_State *L ) {
Get collision info between ray and triangle
-- Failure return nil
- Success return RayCollision
*/
int lmodelsGetRayCollisionTriangle( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetRayCollisionTriangle( Ray ray, Vector3 p1, Vector3 p2, Vector3 p3 )" );
- lua_pushnil( L );
- return 1;
- }
Ray ray = uluaGetRayIndex( L, 1 );
Vector3 p1 = uluaGetVector3Index( L, 2 );
Vector3 p2 = uluaGetVector3Index( L, 3 );
@@ -2675,16 +1742,9 @@ int lmodelsGetRayCollisionTriangle( lua_State *L ) {
Get collision info between ray and quad
-- Failure return nil
- Success return RayCollision
*/
int lmodelsGetRayCollisionQuad( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 )
- || !lua_istable( L, 4 ) || !lua_istable( L, 5 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetRayCollisionQuad( Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4 )" );
- lua_pushnil( L );
- return 1;
- }
Ray ray = uluaGetRayIndex( L, 1 );
Vector3 p1 = uluaGetVector3Index( L, 2 );
Vector3 p2 = uluaGetVector3Index( L, 3 );
diff --git a/src/state.c b/src/state.c
index b6de876..6102a2d 100644
--- a/src/state.c
+++ b/src/state.c
@@ -17,37 +17,8 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
state->resolution = (Vector2){ 800, 600 };
state->luaState = NULL;
state->logLevelInvalid = LOG_ERROR;
- /* 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* ) );
- for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
- state->meshes[i] = NULL;
- state->models[i] = NULL;
- state->animations[i] = NULL;
-
- /* The ones we want to save the first. */
- if ( 0 < i ) {
- 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();
if ( !IsWindowReady() ) {
state->hasWindow = false;
@@ -67,36 +38,6 @@ void stateInitInterpret( int argn, const char **argc ) {
}
void stateFree() {
- for ( int i = 0; i < state->modelCount; ++i ) {
- if ( state->models[i] != NULL ) {
- //TODO Test if UnloadModel causes segfaults on exit.
- UnloadModelKeepMeshes( *state->models[i] );
- // UnloadModel( *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 ) {
- /* Prevent unloading shader that would result in double free when freeing shaders. */
- state->materials[i]->shader.id = rlGetShaderIdDefault();
-
- 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] );
- }
- }
-
if ( IsAudioDeviceReady() ) {
CloseAudioDevice();
}
@@ -107,10 +48,6 @@ void stateFree() {
if ( state->hasWindow ) {
CloseWindow();
}
- free( state->meshes );
- free( state->materials );
- free( state->models );
- free( state->animations );
free( state->exePath );
free( state );
}
diff --git a/src/text.c b/src/text.c
index d0c7835..1f8606e 100644
--- a/src/text.c
+++ b/src/text.c
@@ -40,7 +40,7 @@ int ltextLoadFont( lua_State *L ) {
}
/*
-> font = RL.LoadFontEx( string fileName, int fontSize, int fontChars{} )
+> font = RL.LoadFontEx( string fileName, int fontSize, int{} fontChars )
Load font from file with extended parameters. Loading the default character set
diff --git a/src/textures.c b/src/textures.c
index a66902d..2ebf9cb 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -831,35 +831,21 @@ int ltexturesImageDraw( lua_State *L ) {
}
/*
-> success = RL.ImageDrawTextEx( Image dst, Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
+> RL.ImageDrawTextEx( Image dst, Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
-Draw text ( Custom sprite font ) within an image ( Destination )
-
-- Failure return false
-- Success return true
+Draw text (Custom sprite font) within an image (Destination)
*/
int ltexturesImageDrawTextEx( lua_State *L ) {
- // if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isstring( L, 3 ) || !lua_istable( L, 4 )
- // || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) || !lua_istable( L, 7 ) ) {
- // TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.ImageDrawTextEx( Image dst, Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )" );
- // lua_pushboolean( L, false );
- // return 1;
- // }
- // size_t imageId = lua_tointeger( L, 1 );
- // size_t fontId = lua_tointeger( L, 2 );
- // Vector2 position = uluaGetVector2Index( L, 4 );
- // float fontSize = lua_tonumber( L, 5 );
- // float spacing = lua_tonumber( L, 6 );
- // Color tint = uluaGetColorIndex( L, 7 );
-
- // if ( !validImage( imageId ) || !validFont( fontId ) ) {
- // lua_pushboolean( L, false );
- // return 1;
- // }
- // ImageDrawTextEx( state->images[ imageId ], *state->fonts[ fontId ], lua_tostring( L, 3 ), position, fontSize, spacing, tint );
- // lua_pushboolean( L, true );
+ Image *image = luaL_checkudata( L, 1, "Image" );
+ Font *font = luaL_checkudata( L, 2, "Font" );
+ Vector2 position = uluaGetVector2Index( L, 4 );
+ float fontSize = luaL_checknumber( L, 5 );
+ float spacing = luaL_checknumber( L, 6 );
+ Color tint = uluaGetColorIndex( L, 7 );
- return 1;
+ ImageDrawTextEx( image, *font, luaL_checkstring( L, 3 ), position, fontSize, spacing, tint );
+
+ return 0;
}
/*