Skip to content

Commit e7138a4

Browse files
committed
Fixing return types with pointers
1 parent c8b0c1d commit e7138a4

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

META6.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"libraries/raylib"
3434
],
3535
"test-depends": [],
36-
"version": "0.0.10",
36+
"version": "0.0.11",
3737
"source-url": "https://github.com/vushu/raylib-raku.git",
3838
"builder": "Distribution::Builder::MakeFromJSON",
3939
"build": {

lib/Raylib/Actions.rakumod

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class RaylibActions {
171171
if $<identifier>.made ! @.ignored-functions {
172172
my $return-is-type-value-type = $<type><identifier> && !$<pointer>;
173173
my $made-parameters = $<parameters>.made;
174-
my $func = self.gen-function($<type>, $<identifier>, $<parameters>.made, $return-is-type-value-type);
174+
my $func = self.gen-function($<type>, $<pointer>, $<identifier>, $<parameters>.made, $return-is-type-value-type);
175175
if ($!is-value-type || $return-is-type-value-type) { # checking return type also
176176
$!is-value-type = False;
177177
@.pointerized_bindings.push($func);
@@ -353,8 +353,18 @@ class RaylibActions {
353353
}
354354
}
355355

356-
method get-return-type($return-type) {
357-
my $raku-type = $return-type<identifier> ?? $return-type<identifier>.made !! $return-type.made;
356+
method get-return-type($return-type, $pointer) {
357+
my $raku-type = $return-type.made;
358+
my $is-identifier = False;
359+
if ($return-type<identifier>) {
360+
$is-identifier = True;
361+
$raku-type = $return-type<identifier>.made;
362+
}
363+
364+
if ($pointer && $raku-type ne 'Str' && !$is-identifier) {
365+
return " returns Pointer[$raku-type]";
366+
}
367+
358368
if ($raku-type ne 'void') {
359369
# no returns on void type
360370
return " returns $raku-type";
@@ -369,10 +379,10 @@ class RaylibActions {
369379

370380
}
371381

372-
method gen-function($return-type, $function-name, $parameters, $return-is-type-value-type) {
382+
method gen-function($return-type, $pointer, $function-name, $parameters, $return-is-type-value-type) {
373383
my $pointerize = ($!is-value-type || $return-is-type-value-type) ?? '_pointerized' !! '';
374384
my $params = $parameters;
375-
my $raku-type = self.get-return-type($return-type);
385+
my $raku-type = self.get-return-type($return-type, $pointer);
376386
my $kebab-case-name = self.camelcase-to-kebab($function-name.Str);
377387
return $params
378388
?? "our sub $kebab-case-name ($params)$raku-type is export is native(LIBRAYLIB) is symbol('$function-name$pointerize')\{ * \}"

lib/Raylib/Bindings.rakumod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ our sub set-window-min-size (int32 $width, int32 $height) is export is native(LI
787787
our sub set-window-size (int32 $width, int32 $height) is export is native(LIBRAYLIB) is symbol('SetWindowSize'){ * }
788788
our sub set-window-opacity (num32 $opacity) is export is native(LIBRAYLIB) is symbol('SetWindowOpacity'){ * }
789789
our sub term:<set-window-focused> () is export is native(LIBRAYLIB) is symbol('SetWindowFocused'){ * }
790-
our sub term:<get-window-handle> () is export is native(LIBRAYLIB) is symbol('GetWindowHandle'){ * }
790+
our sub term:<get-window-handle> () returns Pointer[void] is export is native(LIBRAYLIB) is symbol('GetWindowHandle'){ * }
791791
our sub term:<get-screen-width> () returns int32 is export is native(LIBRAYLIB) is symbol('GetScreenWidth'){ * }
792792
our sub term:<get-screen-height> () returns int32 is export is native(LIBRAYLIB) is symbol('GetScreenHeight'){ * }
793793
our sub term:<get-render-width> () returns int32 is export is native(LIBRAYLIB) is symbol('GetRenderWidth'){ * }
@@ -834,8 +834,8 @@ our sub take-screenshot (Str $fileName) is export is native(LIBRAYLIB) is symbol
834834
our sub set-config-flags (uint32 $flags) is export is native(LIBRAYLIB) is symbol('SetConfigFlags'){ * }
835835
our sub trace-log (int32 $logLevel, Str $text, ) is export is native(LIBRAYLIB) is symbol('TraceLog'){ * }
836836
our sub set-trace-log-level (int32 $logLevel) is export is native(LIBRAYLIB) is symbol('SetTraceLogLevel'){ * }
837-
our sub mem-alloc (uint32 $size) is export is native(LIBRAYLIB) is symbol('MemAlloc'){ * }
838-
our sub mem-realloc (Pointer[void] $ptr, uint32 $size) is export is native(LIBRAYLIB) is symbol('MemRealloc'){ * }
837+
our sub mem-alloc (uint32 $size) returns Pointer[void] is export is native(LIBRAYLIB) is symbol('MemAlloc'){ * }
838+
our sub mem-realloc (Pointer[void] $ptr, uint32 $size) returns Pointer[void] is export is native(LIBRAYLIB) is symbol('MemRealloc'){ * }
839839
our sub mem-free (Pointer[void] $ptr, ) is export is native(LIBRAYLIB) is symbol('MemFree'){ * }
840840
our sub open-url (Str $url) is export is native(LIBRAYLIB) is symbol('OpenURL'){ * }
841841
our sub set-trace-log-callback (&trace-log-callback (int32 $logLevel, Str $text, Str $args)) is export is native(LIBRAYLIB) is symbol('SetTraceLogCallback'){ * }
@@ -936,7 +936,7 @@ our sub set-text-line-spacing (int32 $spacing) is export is native(LIBRAYLIB) is
936936
our sub measure-text (Str $text, int32 $fontSize) returns int32 is export is native(LIBRAYLIB) is symbol('MeasureText'){ * }
937937
our sub load-utf8 (Pointer[int32] $codepoints, int32 $length) returns Str is export is native(LIBRAYLIB) is symbol('LoadUTF8'){ * }
938938
our sub unload-utf8 (Str $text) is export is native(LIBRAYLIB) is symbol('UnloadUTF8'){ * }
939-
our sub load-codepoints (Str $text, Pointer[int32] $count, ) returns int32 is export is native(LIBRAYLIB) is symbol('LoadCodepoints'){ * }
939+
our sub load-codepoints (Str $text, Pointer[int32] $count, ) returns Pointer[int32] is export is native(LIBRAYLIB) is symbol('LoadCodepoints'){ * }
940940
our sub unload-codepoints (Pointer[int32] $codepoints, ) is export is native(LIBRAYLIB) is symbol('UnloadCodepoints'){ * }
941941
our sub get-codepoint-count (Str $text) returns int32 is export is native(LIBRAYLIB) is symbol('GetCodepointCount'){ * }
942942
our sub get-codepoint (Str $text, Pointer[int32] $codepointSize, ) returns int32 is export is native(LIBRAYLIB) is symbol('GetCodepoint'){ * }
@@ -1283,7 +1283,7 @@ our sub set-sound-volume (Sound $sound, num32 $volume) is export is native(LIBRA
12831283
our sub set-sound-pitch (Sound $sound, num32 $pitch) is export is native(LIBRAYLIB) is symbol('SetSoundPitch_pointerized'){ * }
12841284
our sub set-sound-pan (Sound $sound, num32 $pan) is export is native(LIBRAYLIB) is symbol('SetSoundPan_pointerized'){ * }
12851285
our sub wave-copy (Wave $wave) returns Wave is export is native(LIBRAYLIB) is symbol('WaveCopy_pointerized'){ * }
1286-
our sub load-wave-samples (Wave $wave) returns num32 is export is native(LIBRAYLIB) is symbol('LoadWaveSamples_pointerized'){ * }
1286+
our sub load-wave-samples (Wave $wave) returns Pointer[num32] is export is native(LIBRAYLIB) is symbol('LoadWaveSamples_pointerized'){ * }
12871287
our sub load-music-stream (Str $fileName) returns Music is export is native(LIBRAYLIB) is symbol('LoadMusicStream_pointerized'){ * }
12881288
our sub load-music-stream-from-memory (Str $fileType, uint8 $data is rw, int32 $dataSize) returns Music is export is native(LIBRAYLIB) is symbol('LoadMusicStreamFromMemory_pointerized'){ * }
12891289
our sub is-music-ready (Music $music) returns bool is export is native(LIBRAYLIB) is symbol('IsMusicReady_pointerized'){ * }

lib/Raylib/Generator.rakumod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sub generate-bindings($raylib-h-file, $output-dir) is export {
1212

1313
my $file = open "lib/Raylib/Bindings.rakumod", :w;
1414
$file.say(generation-message);
15-
$file.say("unit module Raylib::Bindings:ver<0.0.10>:auth<zef:vushu>;");
15+
$file.say("unit module Raylib::Bindings:ver<0.0.11>:auth<zef:vushu>;");
1616
$file.say("use NativeCall;");
1717
$file.say("constant LIBRAYLIB = %\?RESOURCES<libraries/raylib>;");
1818
for $actions.bindings -> $binding {

0 commit comments

Comments
 (0)