File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -297,6 +297,33 @@ to callbacks.
297
297
298
298
TBD
299
299
300
+ = head2 Calling into the standard library
301
+
302
+ If you want to call a C function that's already loaded, either from the
303
+ standard library or from your own program, you can pass the C < Str > type object
304
+ as the argument to C < is native > , so C < is native(Str) > .
305
+
306
+ For example on a UNIX-like operating system, you could use the following code
307
+ to print the home directory of the current user:
308
+
309
+ use NativeCall;
310
+ my class PwStruct is repr('CStruct') {
311
+ has Str $.pw_name;
312
+ has Str $.pw_passwd;
313
+ has uint32 $.pw_uid;
314
+ has uint32 $.pw_gid;
315
+ has Str $.pw_gecos;
316
+ has Str $.pw_dir;
317
+ has Str $.pw_shell;
318
+ }
319
+ sub getuid() returns uint32 is native(Str) {};
320
+ sub getpwuid(int $uid) returns PwStruct is native(Str) {};
321
+
322
+ say getpwuid(getuid()).pw_dir;
323
+
324
+ Though of course C < $*HOME > is a much easier way :-)
325
+
326
+
300
327
= head1 Exported variables
301
328
302
329
Variables exported by a library -- also named "global" or "extern"
You can’t perform that action at this time.
0 commit comments