小编ara*_*ren的帖子

使用NativeCall在不同平台上处理C typedef

有没有一种方便的方法来处理C typedef,它可能在各种平台上有不同的价值?

例如

#if defined(_WIN32)
    #define foo_t int32_t
#elif defined(_WIN64)
    #define foo_t int64_t
#else
    #define foo_t long
#endif

void handle_foo(foo_t* in) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

目前我在Perl 6中处理这个问题

sub handle_foo32(int32 is rw) is native(Str) { * }
sub handle_foo64(int64 is rw) is native(Str) { * }
sub handle_foo00(long  is rw) is native(Str) { * }

sub handle-foo(Int $in) {
    if $*DISTRO.is-win {
        given $*KERNEL.bits {
            when 32 {
                handle_foo32(my int32 $ = $in);
            }
            when 64 {
                handle_foo64(my int64 $ = $in); …
Run Code Online (Sandbox Code Playgroud)

c perl6 nativecall raku

10
推荐指数
1
解决办法
135
查看次数

在两个模块之间使用角色时出现问题

我正在制作一个具有多模块文件的模块,并且在不同模块中使用角色时遇到了这个问题.

例如,我们有两个模块Foo和Bar,每个模块都有一个角色.

module Foo { 
    role foo is export {

    }  
}

module Bar { 
    import Foo; 

    role bar is export does foo {

    }
} 

import Foo;
import Bar;

sub f(foo \k) { }

f(bar.new);
Run Code Online (Sandbox Code Playgroud)

我认为代码很好,但rakudo说它认为bar不是foo而且拒绝编译.

这有什么不对?

perl6

5
推荐指数
2
解决办法
154
查看次数

标签 统计

perl6 ×2

c ×1

nativecall ×1

raku ×1