加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

ncurses – 本机调用接口:如何翻译“wchar_t”?

发布时间:2020-12-15 23:36:09 所属栏目:大数据 来源:网络整理
导读:我想使用ncurses int addwstr(const wchar_t * wstr);功能在Perl6中. 我怎么能得到一个Perl 6签名来传达addwstr的const wchar_t * wstr? use v6;use NativeCall;constant LIB = 'libncursesw.so.5';sub addwstr( ? ) returns int32 is native(LIB) is expor
我想使用ncurses int addwstr(const wchar_t * wstr);功能在Perl6中.

我怎么能得到一个Perl 6签名来传达addwstr的const wchar_t * wstr?

use v6;
use NativeCall;

constant LIB = 'libncursesw.so.5';

sub addwstr(  ?  ) returns int32 is native(LIB) is export {*};

解决方法

wchar_t在我的机器上是32位.从 NativeCall doco开始,您可以声明它们的数组,数组名称将作为指针;

#!/usr/bin/env perl6
use v6;
use NCurses;                   # To get iniscr(),endwin() etc
use NativeCall;

# Need to run setlocale from the C library
my int32 constant LC_ALL = 6;           # From locale.h
my sub setlocale(int32,Str) returns Str is native(Str) { * }

constant LIB = 'libncursesw.so.5';
sub addwstr(CArray[int32]) returns int32 is native(LIB) { * }

# The smiley        : Codepoint 0x263a
# Latin space       : Codepoint 0x20  (Ascii decimal ord 32)
# Check mark (tick) : Codepoint 0x2713

my CArray[int32] $wchar_str .= new(0x263a,0x20,0x2713);

setlocale(LC_ALL,"");
initscr();
move(2,2);
addwstr( $wchar_str );
nc_refresh;
while getch() < 0 {};
endwin;

这会在我的机器上打印“??”.如果没有调用setlocale,它就无法工作.

顺便说一下,你不必使用’w’函数 – 你可以只传递普通的perl6字符串(大概是编码的UTF-8),它只是起作用.这产生了相同的结果;

#!/usr/bin/env perl6
use v6;
use NCurses;
use NativeCall;

# Need to run setlocale from the standard C library
my int32 constant LC_ALL = 6;           # From locale.h
my sub setlocale(int32,Str) returns Str is native(Str) { * }

my $ordinary_scalar = "? ?";

setlocale(LC_ALL,2);
addstr( $ordinary_scalar );   # No 'w' necessary
nc_refresh;
while getch() < 0 {};
endwin;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读