develooper Front page | perl.perl6.users | Postings from December 2019

I need helping understanding a pointer example

Thread Next
From:
Todd Chester via perl6-users
Date:
December 31, 2019 05:14
Subject:
I need helping understanding a pointer example
Message ID:
a60d7213-9044-d022-ddb1-7c0dc83e3b9c@zoho.com
Hi All,

Over at

https://docs.raku.org/language/nativecall.html#Basic_use_of_pointers

There is an example:

    useNativeCall;
    classFooHandleisrepr('CPointer') {
    # Here are the actual NativeCall functions.
    subFoo_init() returnsFooHandleisnative("foo") {*}
    subFoo_free(FooHandle) isnative("foo") {*}
    subFoo_query(FooHandle, Str) returnsint8isnative("foo") {*}
    subFoo_close(FooHandle) returnsint8isnative("foo") {*}
    # Here are the methods we use to expose it to the outside world.
    methodnew{
    Foo_init();
    }
    methodquery(Str$stmt) {
    Foo_query(self, $stmt);
    }
    methodclose{
    Foo_close(self);
    }
    # Free data when the object is garbage collected.
    submethodDESTROY{
    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.
    subFoo_init() returnsFooHandleisnative("foo") {*}
    subFoo_free(FooHandle) isnative("foo") {*}
    subFoo_query(FooHandle, Str) returnsint8isnative("foo") {*}
    subFoo_close(FooHandle) returnsint8isnative("foo") {*}

He called subs exported from NativeCall "foo*"?

What does hemean 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 ?
subFoo_init() returnsFooHandleisnative("foo") {*}`

4) what is ?
     subFoo_free(FooHandle) isnative("foo") {*}

5) what is ?
subFoo_query(FooHandle, Str) returnsint8isnative("foo") {*}

6) what is ?
subFoo_close(FooHandle) returnsint8isnative("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?

    methodquery(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




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About