[Glass] Passing a enum element to a C library

bruno buzzi brassesco smalltalk at adinet.com.uy
Wed Jul 1 18:51:20 PDT 2020


James,

After replacing #'prt' with #'uint32' and initializing the wrapper the C 
call work as expected :)
Excellent !
regards,
bruno

On 1/7/2020 21:27, Smalltalk at JGFoster.net wrote:
> It seems to me that the function should be interpreted as (#’ptr’ #’int’ #’ptr’) since an enum is simply an integer. Try passing it just 0 and see if that goes through.
>
> James
>
>> On Jul 1, 2020, at 4:41 PM, bruno buzzi brassesco via Glass <glass at lists.gemtalksystems.com> wrote:
>>
>> Hi,
>>
>> How to pass an enum element to a C library.
>> C function signature:
>> int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
>>
>> The enum is defined as:
>> enum ssh_options_e {
>>   SSH_OPTIONS_HOST,
>>   SSH_OPTIONS_PORT}
>>
>> An any C call is like:
>> ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
>>
>> GS generated wrapper:
>> ssh_options_set_: session _: type _: value
>>     "Interpreted as #int32 from #( #'ptr' #'ptr' #'ptr' )"
>>     ^Functionssh_options_set callWith: { session. type. value }
>>
>> In GS i tried something like:
>> myLibrary ssh_options_set_: session _: optionHost _: hostName
>> where
>> session: is created in another successful call to myLibrary
>>
>> optionHost:
>> cStructPointer := CByteArray gcMalloc: 8.
>> cStructPointer uint64At: 0 put: 0. "0 correspond to SSH_OPTIONS_HOST - maybe i'm wrong"
>>
>> hostName: CByteArray withAll: 'localhost'
>>
>> But it seems that something is wrong. The chapter 18 do something like this with another library.
>> So [optionHost] or [hostName] has a wrong value...
>> For now no successful call passing an enum element.
>>
>> Now back to fight with C :)
>>
>> regards,
>> bruno
>>
>> _______________________________________________
>> Glass mailing list
>> Glass at lists.gemtalksystems.com
>> https://lists.gemtalksystems.com/mailman/listinfo/glass


More information about the Glass mailing list