Method declares a method as opposed to a function. The difference is that
in a method, the first argument passed to the function is bound to `self`,
which represents the object the call was made on.

In traditional perl style, when you call a method on an object
`your.face('scrambled eggs')`, it actually calls `face(your, 'scrambled
eggs')`. At least that's the semantics in Perl.

On Tue, Dec 31, 2019, 07:15 Todd Chester via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Over at
>
>    https://docs.raku.org/language/nativecall.html#Basic_use_of_pointers
>
> There is an example:
>
> use NativeCall;
>
> class FooHandle is repr('CPointer') {
>     # Here are the actual NativeCall functions.
>     sub Foo_init() returns FooHandle is native("foo") { * }
>     sub Foo_free(FooHandle) is native("foo") { * }
>     sub Foo_query(FooHandle, Str) returns int8 is native("foo") { * }
>     sub Foo_close(FooHandle) returns int8 is native("foo") { * }
>
>     # Here are the methods we use to expose it to the outside world.
>     method new {
>         Foo_init();
>     }
>
>     method query(Str $stmt) {
>         Foo_query(self, $stmt);
>     }
>
>     method close {
>         Foo_close(self);
>     }
>
>     # Free data when the object is garbage collected.
>     submethod DESTROY {
>         Foo_free(self);
>     }
> }
>
> I just can't keeping my head what is going on.
>
> Questions:
>
> 1) How can I get a list of what types are imported (like Pointer
> and CArray) when I `use nativeCall` and what their definitions
> are?
>
> 2) on
>
> # Here are the actual NativeCall functions.
>     sub Foo_init() returns FooHandle is native("foo") { * }
>     sub Foo_free(FooHandle) is native("foo") { * }
>     sub Foo_query(FooHandle, Str) returns int8 is native("foo") { * }
>     sub Foo_close(FooHandle) returns int8 is native("foo") { * }
>
> He called subs exported from NativeCall "foo*"?
>
> What does he mean by `# Here are the actual NativeCall functions.`?
>
> If he means these are fictitious "C" calls formatted into NativeCall
> format, he in NOT BEING HELPFUL.  I need to see BOTH the actual "C"
> calls as well as how he formatted them to NativeCall.
>
> 3) what is ?
>     sub Foo_init() returns FooHandle is native("foo") { * }`
>
> 4) what is ?
>     sub Foo_free(FooHandle) is native("foo") { * }
>
> 5) what is ?
>     sub Foo_query(FooHandle, Str) returns int8 is native("foo") { * }
>
> 6) what is ?
>     sub Foo_close(FooHandle) returns int8 is native("foo") { * }
>
> 7) A) in the below, where did `self` come from?  Is it a type?
>
>    B) not to ask too stupid a question, but what does "method"
>         do for me?
>
> method query(Str $stmt) {
>         Foo_query(self, $stmt);
>     }
>
>
> Just a general comment:
>
> It would be wonderful if the docs would show actual "C" calls
> from something like Kernel32.dll and how to access them
> with NativeCall.
>
> For instance:
>
> LSTATUS RegQueryValueExA( HKEY hKey, LPCSTR lpValueName, LPDWORD
> lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData );
>
> The example should go over what to give NativeCall for
> all of the above "C" types.
>
> Yours in Confusion,,
> -T
>
>
>
>

Reply via email to