summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md4
-rw-r--r--ReiLua_API.lua5
-rw-r--r--changelog2
-rw-r--r--devnotes1
-rw-r--r--examples/2D_lights/main.lua24
-rw-r--r--examples/resources/lib/color.lua3
-rw-r--r--examples/resources/lib/matrix.lua5
-rw-r--r--examples/resources/lib/quaternion.lua3
-rw-r--r--examples/resources/lib/rectangle.lua3
-rw-r--r--examples/resources/lib/rune.lua97
-rw-r--r--examples/resources/lib/utillib.lua4
-rw-r--r--examples/resources/lib/vector2.lua3
-rw-r--r--examples/resources/lib/vector3.lua3
-rw-r--r--src/text.c15
14 files changed, 145 insertions, 27 deletions
diff --git a/API.md b/API.md
index 70a75f2..06fc8fb 100644
--- a/API.md
+++ b/API.md
@@ -6660,11 +6660,11 @@ Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failu
---
-> string, utf8Size = RL.CodepointToUTF8( int codepoint )
+> string = RL.CodepointToUTF8( int codepoint )
Encode one codepoint into UTF-8 byte array
-- Success return string, int
+- Success return string
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index eb3f1b5..1db9119 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -3993,10 +3993,9 @@ function RL.GetCodepointNext( text ) end
function RL.GetCodepointPrevious( text ) end
---Encode one codepoint into UTF-8 byte array
----- Success return string, int
+---- Success return string
---@param codepoint integer
----@return any string
----@return any utf8Size
+---@return any string
function RL.CodepointToUTF8( codepoint ) end
-- Text - Text strings management functions (no UTF-8 strings, only byte chars)
diff --git a/changelog b/changelog
index 2a72fc7..bc5d451 100644
--- a/changelog
+++ b/changelog
@@ -34,6 +34,7 @@ KEY CHANGES:
- CHANGE: Raygui lib refactoring.
- ADDED: Raygui lib extensions property list.
- ADDED: Text codepoints management functions.
+ - ADDED: Rune, UTF8 lib.
DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
@@ -66,6 +67,7 @@ DETAILED CHANGES:
- ADDED: LoadBufferFromString, LoadWaveFromMemory and LoadMusicStreamFromMemory.
- CHANGE: GetGlyphInfo and GetGlyphInfoByIndex return glyphInfo as lightuserdata.
- ADDED: TextInsert and TextSplit.
+ - ADDED: __concat for variable wrapper libraries.
------------------------------------------------------------------------
Release: ReiLua version 0.6.0 Using Raylib 4.5
diff --git a/devnotes b/devnotes
index bf24d14..dd33255 100644
--- a/devnotes
+++ b/devnotes
@@ -23,7 +23,6 @@ Backlog {
}
Bugs {
- * Test if Rectangle:fit works with negative position.
}
Needs Testing {
diff --git a/examples/2D_lights/main.lua b/examples/2D_lights/main.lua
index d3aa4e9..9c033eb 100644
--- a/examples/2D_lights/main.lua
+++ b/examples/2D_lights/main.lua
@@ -103,21 +103,21 @@ function RL.init()
createShadowMesh()
- -- addLight( Vector2:new( 230, 480 ), Color:new( RL.ORANGE ), 512 )
- -- addLight( Vector2:new( 600, 200 ), Color:new( RL.RED ), 512 )
- -- addLight( Vector2:new( 384, 520 ), Color:new( RL.GREEN ), 400 )
- -- addLight( Vector2:new( 880, 750 ), Color:new( RL.BLUE ), 300 )
- -- addLight( Vector2:new( 800, 500 ), Color:new( RL.PURPLE ), 512 )
- -- addLight( Vector2:new( 200, 760 ), Color:new( RL.WHITE ), 400 )
+ addLight( Vector2:new( 230, 480 ), Color:new( RL.ORANGE ), 512 )
+ addLight( Vector2:new( 600, 200 ), Color:new( RL.RED ), 512 )
+ addLight( Vector2:new( 384, 520 ), Color:new( RL.GREEN ), 400 )
+ addLight( Vector2:new( 880, 750 ), Color:new( RL.BLUE ), 300 )
+ addLight( Vector2:new( 800, 500 ), Color:new( RL.PURPLE ), 512 )
+ addLight( Vector2:new( 200, 760 ), Color:new( RL.WHITE ), 400 )
-- Stress test
- for i = 1, 300 do
- addLight( Vector2:new( math.random( 20, RESOLUTION.x - 20 ), math.random( 20, RESOLUTION.y - 20 ) ),
- Color:new( { math.random( 40, 255 ), math.random( 40, 255 ), math.random( 40, 255 ), 255 } ),
- 128
- )
- end
+ -- for i = 1, 300 do
+ -- addLight( Vector2:new( math.random( 20, RESOLUTION.x - 20 ), math.random( 20, RESOLUTION.y - 20 ) ),
+ -- Color:new( { math.random( 40, 255 ), math.random( 40, 255 ), math.random( 40, 255 ), 255 } ),
+ -- 128
+ -- )
+ -- end
-- Camera for shadow rendering.
camera = RL.CreateCamera3D()
diff --git a/examples/resources/lib/color.lua b/examples/resources/lib/color.lua
index 1fb06a1..1344dba 100644
--- a/examples/resources/lib/color.lua
+++ b/examples/resources/lib/color.lua
@@ -41,6 +41,9 @@ Color.meta = {
and math.floor( c1.b ) == math.floor( c2.b )
and math.floor( c1.a ) == math.floor( c2.a )
end,
+ __concat = function( a, b )
+ return tostring( a )..tostring( b )
+ end,
}
function Color:new( r, g, b, a )
diff --git a/examples/resources/lib/matrix.lua b/examples/resources/lib/matrix.lua
index 3b68118..3128610 100644
--- a/examples/resources/lib/matrix.lua
+++ b/examples/resources/lib/matrix.lua
@@ -41,7 +41,10 @@ Matrix.meta = {
end,
__mul = function( m1, m2 )
return Matrix:new( RL.MatrixMultiply( m1, m2 ) )
- end
+ end,
+ __concat = function( a, b )
+ return tostring( a )..tostring( b )
+ end,
}
function Matrix:new( m )
diff --git a/examples/resources/lib/quaternion.lua b/examples/resources/lib/quaternion.lua
index a545838..e85415c 100644
--- a/examples/resources/lib/quaternion.lua
+++ b/examples/resources/lib/quaternion.lua
@@ -33,6 +33,9 @@ Quaternion.meta = {
__eq = function( q1, q2 )
return RL.QuaternionEquals( q1, q2 ) == 1
end,
+ __concat = function( a, b )
+ return tostring( a )..tostring( b )
+ end,
}
function Quaternion:new( x, y, z, w )
diff --git a/examples/resources/lib/rectangle.lua b/examples/resources/lib/rectangle.lua
index ba1f9c6..a37c1c1 100644
--- a/examples/resources/lib/rectangle.lua
+++ b/examples/resources/lib/rectangle.lua
@@ -38,6 +38,9 @@ Rectangle.meta = {
__eq = function( r1, r2 )
return RL.Vector2Equals( { r1.x, r1.y }, { r2.x, r2.y } ) and RL.Vector2Equals( { r1.width, r1.height }, { r2.width, r2.height } )
end,
+ __concat = function( a, b )
+ return tostring( a )..tostring( b )
+ end,
}
function Rectangle:new( x, y, width, height )
diff --git a/examples/resources/lib/rune.lua b/examples/resources/lib/rune.lua
new file mode 100644
index 0000000..5809da3
--- /dev/null
+++ b/examples/resources/lib/rune.lua
@@ -0,0 +1,97 @@
+-- For luaJit compatibility.
+if table.unpack == nil then
+ table.unpack = unpack
+end
+
+local Rune = {}
+Rune.meta = {
+ __index = Rune,
+ __tostring = function( r )
+ return r.string
+ end,
+ __len = function( r )
+ return RL.GetCodepointCount( r.string )
+ end,
+ __eq = function( r1, r2 )
+ return r1.string == r2.string
+ end,
+ __concat = function( a, b )
+ return tostring( a )..tostring( b )
+ end,
+}
+
+function Rune:new( string )
+ if type( string ) == "table" then
+ string = RL.LoadUTF8( string )
+ elseif type( string ) == "nil" then
+ string = ""
+ end
+
+ local object = setmetatable( {}, Rune.meta )
+
+ object.string = string
+
+ return object
+end
+
+function Rune:set( string )
+ if type( string ) == "table" then
+ string = RL.LoadUTF8( string )
+ elseif type( string ) == "nil" then
+ string = ""
+ end
+
+ self.string = string
+end
+
+function Rune:clone()
+ return Rune:new( self.string )
+end
+
+function Rune:len()
+ return RL.GetCodepointCount( self.string )
+end
+
+function Rune:getCodepoints()
+ return RL.LoadCodepoints( self.string )
+end
+
+function Rune:getCodepoint( index )
+ local codepoint = RL.GetCodepoint( self:sub( index, index ) )
+ return codepoint
+end
+
+function Rune:getCodepointSize( index )
+ local _, codepointSize = RL.GetCodepoint( self:sub( index, index ) )
+ return codepointSize
+end
+
+function Rune:insert( pos, string )
+ local codepoints = self:getCodepoints()
+
+ for i, codepoint in ipairs( RL.LoadCodepoints( string ) ) do
+ table.insert( codepoints, pos + i - 1, codepoint )
+ end
+ self.string = RL.LoadUTF8( codepoints )
+end
+
+function Rune:sub( i, j )
+ local codepoints = self:getCodepoints()
+ return RL.LoadUTF8( { table.unpack( codepoints, i, j ) } )
+end
+
+function Rune:gsub( pattern, repl )
+ return string.gsub( self.string, pattern, repl )
+end
+
+function Rune:split( delimiter )
+ local splits = {}
+
+ for str in string.gmatch( self.string, "([^"..delimiter.."]+)" ) do
+ table.insert( splits, str )
+ end
+
+ return splits
+end
+
+return Rune
diff --git a/examples/resources/lib/utillib.lua b/examples/resources/lib/utillib.lua
index 95184b0..0b54e12 100644
--- a/examples/resources/lib/utillib.lua
+++ b/examples/resources/lib/utillib.lua
@@ -83,14 +83,14 @@ function utillib.tableLen( t )
return count
end
-function utillib.split( str, sep )
+function utillib.split( string, sep )
if sep == nil then
sep = "%s"
end
local t = {}
- for str in string.gmatch( str, "([^"..sep.."]+)" ) do
+ for str in string.gmatch( string, "([^"..sep.."]+)" ) do
table.insert( t, str )
end
diff --git a/examples/resources/lib/vector2.lua b/examples/resources/lib/vector2.lua
index 15934fb..065e556 100644
--- a/examples/resources/lib/vector2.lua
+++ b/examples/resources/lib/vector2.lua
@@ -36,6 +36,9 @@ Vector2.meta = {
__eq = function( v1, v2 )
return RL.Vector2Equals( v1, v2 ) == 1
end,
+ __concat = function( a, b )
+ return tostring( a )..tostring( b )
+ end,
}
function Vector2:new( x, y )
diff --git a/examples/resources/lib/vector3.lua b/examples/resources/lib/vector3.lua
index ca294e9..9b77881 100644
--- a/examples/resources/lib/vector3.lua
+++ b/examples/resources/lib/vector3.lua
@@ -38,6 +38,9 @@ Vector3.meta = {
__eq = function( v1, v2 )
return RL.Vector3Equals( v1, v2 ) == 1
end,
+ __concat = function( a, b )
+ return tostring( a )..tostring( b )
+ end,
}
function Vector3:new( x, y, z )
diff --git a/src/text.c b/src/text.c
index e214c70..8981a9a 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1120,20 +1120,23 @@ int ltextGetCodepointPrevious( lua_State *L ) {
}
/*
-> string, utf8Size = RL.CodepointToUTF8( int codepoint )
+> string = RL.CodepointToUTF8( int codepoint )
Encode one codepoint into UTF-8 byte array
-- Success return string, int
+- Success return string
*/
int ltextCodepointToUTF8( lua_State *L ) {
int codepoint = luaL_checkinteger( L, 1 );
int utf8Size = 0;
- lua_pushstring( L, CodepointToUTF8( codepoint, &utf8Size ) );
- lua_pushinteger( L, utf8Size );
+ char text[5] = { '\0' };
+ const char* utf8 = CodepointToUTF8( codepoint, &utf8Size );
+ memcpy( text, utf8, utf8Size );
- return 2;
+ lua_pushstring( L, text );
+
+ return 1;
}
/*
@@ -1155,7 +1158,7 @@ int ltextTextInsert( lua_State *L ) {
// char* result = TextInsert( text, insert, position ); // Bug in the raylib implementation.
int textLen = TextLength( text );
- int insertLen = TextLength( insert );
+ int insertLen = TextLength( insert );
char* result = RL_MALLOC( textLen + insertLen + 1 );
memcpy( result, text, position );