Skip to content

Commit

Permalink
Fixing return types with pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
vushu committed Nov 14, 2023
1 parent c8b0c1d commit e7138a4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"libraries/raylib"
],
"test-depends": [],
"version": "0.0.10",
"version": "0.0.11",
"source-url": "https://github.com/vushu/raylib-raku.git",
"builder": "Distribution::Builder::MakeFromJSON",
"build": {
Expand Down
20 changes: 15 additions & 5 deletions lib/Raylib/Actions.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class RaylibActions {
if $<identifier>.made ! @.ignored-functions {
my $return-is-type-value-type = $<type><identifier> && !$<pointer>;
my $made-parameters = $<parameters>.made;
my $func = self.gen-function($<type>, $<identifier>, $<parameters>.made, $return-is-type-value-type);
my $func = self.gen-function($<type>, $<pointer>, $<identifier>, $<parameters>.made, $return-is-type-value-type);
if ($!is-value-type || $return-is-type-value-type) { # checking return type also
$!is-value-type = False;
@.pointerized_bindings.push($func);
Expand Down Expand Up @@ -353,8 +353,18 @@ class RaylibActions {
}
}

method get-return-type($return-type) {
my $raku-type = $return-type<identifier> ?? $return-type<identifier>.made !! $return-type.made;
method get-return-type($return-type, $pointer) {
my $raku-type = $return-type.made;
my $is-identifier = False;
if ($return-type<identifier>) {
$is-identifier = True;
$raku-type = $return-type<identifier>.made;
}

if ($pointer && $raku-type ne 'Str' && !$is-identifier) {
return " returns Pointer[$raku-type]";
}

if ($raku-type ne 'void') {
# no returns on void type
return " returns $raku-type";
Expand All @@ -369,10 +379,10 @@ class RaylibActions {

}

method gen-function($return-type, $function-name, $parameters, $return-is-type-value-type) {
method gen-function($return-type, $pointer, $function-name, $parameters, $return-is-type-value-type) {
my $pointerize = ($!is-value-type || $return-is-type-value-type) ?? '_pointerized' !! '';
my $params = $parameters;
my $raku-type = self.get-return-type($return-type);
my $raku-type = self.get-return-type($return-type, $pointer);
my $kebab-case-name = self.camelcase-to-kebab($function-name.Str);
return $params
?? "our sub $kebab-case-name ($params)$raku-type is export is native(LIBRAYLIB) is symbol('$function-name$pointerize')\{ * \}"
Expand Down
10 changes: 5 additions & 5 deletions lib/Raylib/Bindings.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ our sub set-window-min-size (int32 $width, int32 $height) is export is native(LI
our sub set-window-size (int32 $width, int32 $height) is export is native(LIBRAYLIB) is symbol('SetWindowSize'){ * }
our sub set-window-opacity (num32 $opacity) is export is native(LIBRAYLIB) is symbol('SetWindowOpacity'){ * }
our sub term:<set-window-focused> () is export is native(LIBRAYLIB) is symbol('SetWindowFocused'){ * }
our sub term:<get-window-handle> () is export is native(LIBRAYLIB) is symbol('GetWindowHandle'){ * }
our sub term:<get-window-handle> () returns Pointer[void] is export is native(LIBRAYLIB) is symbol('GetWindowHandle'){ * }
our sub term:<get-screen-width> () returns int32 is export is native(LIBRAYLIB) is symbol('GetScreenWidth'){ * }
our sub term:<get-screen-height> () returns int32 is export is native(LIBRAYLIB) is symbol('GetScreenHeight'){ * }
our sub term:<get-render-width> () returns int32 is export is native(LIBRAYLIB) is symbol('GetRenderWidth'){ * }
Expand Down Expand Up @@ -834,8 +834,8 @@ our sub take-screenshot (Str $fileName) is export is native(LIBRAYLIB) is symbol
our sub set-config-flags (uint32 $flags) is export is native(LIBRAYLIB) is symbol('SetConfigFlags'){ * }
our sub trace-log (int32 $logLevel, Str $text, ) is export is native(LIBRAYLIB) is symbol('TraceLog'){ * }
our sub set-trace-log-level (int32 $logLevel) is export is native(LIBRAYLIB) is symbol('SetTraceLogLevel'){ * }
our sub mem-alloc (uint32 $size) is export is native(LIBRAYLIB) is symbol('MemAlloc'){ * }
our sub mem-realloc (Pointer[void] $ptr, uint32 $size) is export is native(LIBRAYLIB) is symbol('MemRealloc'){ * }
our sub mem-alloc (uint32 $size) returns Pointer[void] is export is native(LIBRAYLIB) is symbol('MemAlloc'){ * }
our sub mem-realloc (Pointer[void] $ptr, uint32 $size) returns Pointer[void] is export is native(LIBRAYLIB) is symbol('MemRealloc'){ * }
our sub mem-free (Pointer[void] $ptr, ) is export is native(LIBRAYLIB) is symbol('MemFree'){ * }
our sub open-url (Str $url) is export is native(LIBRAYLIB) is symbol('OpenURL'){ * }
our sub set-trace-log-callback (&trace-log-callback (int32 $logLevel, Str $text, Str $args)) is export is native(LIBRAYLIB) is symbol('SetTraceLogCallback'){ * }
Expand Down Expand Up @@ -936,7 +936,7 @@ our sub set-text-line-spacing (int32 $spacing) is export is native(LIBRAYLIB) is
our sub measure-text (Str $text, int32 $fontSize) returns int32 is export is native(LIBRAYLIB) is symbol('MeasureText'){ * }
our sub load-utf8 (Pointer[int32] $codepoints, int32 $length) returns Str is export is native(LIBRAYLIB) is symbol('LoadUTF8'){ * }
our sub unload-utf8 (Str $text) is export is native(LIBRAYLIB) is symbol('UnloadUTF8'){ * }
our sub load-codepoints (Str $text, Pointer[int32] $count, ) returns int32 is export is native(LIBRAYLIB) is symbol('LoadCodepoints'){ * }
our sub load-codepoints (Str $text, Pointer[int32] $count, ) returns Pointer[int32] is export is native(LIBRAYLIB) is symbol('LoadCodepoints'){ * }
our sub unload-codepoints (Pointer[int32] $codepoints, ) is export is native(LIBRAYLIB) is symbol('UnloadCodepoints'){ * }
our sub get-codepoint-count (Str $text) returns int32 is export is native(LIBRAYLIB) is symbol('GetCodepointCount'){ * }
our sub get-codepoint (Str $text, Pointer[int32] $codepointSize, ) returns int32 is export is native(LIBRAYLIB) is symbol('GetCodepoint'){ * }
Expand Down Expand Up @@ -1283,7 +1283,7 @@ our sub set-sound-volume (Sound $sound, num32 $volume) is export is native(LIBRA
our sub set-sound-pitch (Sound $sound, num32 $pitch) is export is native(LIBRAYLIB) is symbol('SetSoundPitch_pointerized'){ * }
our sub set-sound-pan (Sound $sound, num32 $pan) is export is native(LIBRAYLIB) is symbol('SetSoundPan_pointerized'){ * }
our sub wave-copy (Wave $wave) returns Wave is export is native(LIBRAYLIB) is symbol('WaveCopy_pointerized'){ * }
our sub load-wave-samples (Wave $wave) returns num32 is export is native(LIBRAYLIB) is symbol('LoadWaveSamples_pointerized'){ * }
our sub load-wave-samples (Wave $wave) returns Pointer[num32] is export is native(LIBRAYLIB) is symbol('LoadWaveSamples_pointerized'){ * }
our sub load-music-stream (Str $fileName) returns Music is export is native(LIBRAYLIB) is symbol('LoadMusicStream_pointerized'){ * }
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'){ * }
our sub is-music-ready (Music $music) returns bool is export is native(LIBRAYLIB) is symbol('IsMusicReady_pointerized'){ * }
Expand Down
2 changes: 1 addition & 1 deletion lib/Raylib/Generator.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sub generate-bindings($raylib-h-file, $output-dir) is export {

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

0 comments on commit e7138a4

Please sign in to comment.