<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1141" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">Hi all!</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"></FONT></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">I’m exploring how to use existing libraries of C/C++ code 
within Squeak and my problem is about how to create oops directly on the plugin 
side and then return them to Squeak.<?xml:namespace prefix = o ns = 
"urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">It’s easy to return integer values created on the plugin 
side (if the values are within the 31-bit range). The integer value is stored in 
the oop header directly. Then we can use the convenient function 
‘integerObjectOf’ for creating the oop from the plugin 
side:<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">:<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">/*The ‘SmallInteger’ oop*/<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">int<SPAN style="mso-spacerun: yes">&nbsp; 
</SPAN>_return_value;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">_return_value = 
interpreterProxy-&gt;integerObjectOf(17);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">interpreterProxy-&gt;popthenPush(1, 
_return_value);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">But what about the other cases, when I want to return 
other ‘primitive’ data types created on the plugin side, which have their 
equivalence in Squeak, Strings, Arrays, etc. I’ve found out that the following 
code works for returning a native c-string, but I wonder, is there a more 
general, easier way of doing it, like the ‘integerObjectOf(aCInteger) 
function?:<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=SV 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt"><FONT 
face="Times New Roman">:<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=SV 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt"><FONT 
face="Times New Roman">char* aCString;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=SV 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt"><FONT 
face="Times New Roman">int aStringOop;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=SV 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt"><FONT 
face="Times New Roman">char* aStringOopPtr;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=SV 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">/*The c-function I want to use from 
Squeak*/.<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">aCString = 
myCStringFunction();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt; mso-layout-grid-align: none"><SPAN 
lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">/*Creation of the String object for the Squeak side, 
which is an oop pointing to its object header. “This operation does not execute 
initialization code typically associated<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt; mso-layout-grid-align: none"><SPAN 
lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">with the object class, however it merely allocates the 
space and initializes<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">all instance variables to nil..” 
(Greenberg)*/<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">aStringOop = 
interpreterProxy-&gt;instantiateClassindexableSize(interpreterProxy-&gt;classString(),<SPAN 
style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"><SPAN 
style="mso-spacerun: yes"></SPAN>strlen(aCString));<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt; mso-layout-grid-align: none"><SPAN 
lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">/*C pointer to the first indexable oop stored in 
the<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">variable portion of the object 
‘aStringOop’*/<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">aStringOopPtr = ((char *) 
(interpreterProxy-&gt;firstIndexableField(aStringOop)));<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">/*Filling ’aStringOop’ with the actual string value from 
‘aCString’*/<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=SV 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt"><FONT 
face="Times New Roman">strcpy(aStringOopPtr, 
aCString);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">/*Returning a String object to 
Squeak*/<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">interpreterProxy-&gt;popthenPush(1, 
aStringOop);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">In the first ‘round’ I tried the ‘TestInterpreterPlugin’ 
for generating the c-code, easy and lazy ;-):<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">primCFunction<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>| aCString |<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>self var: #aCString declareC: 'char* 
aCString'.<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>self<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>primitive: 'primCFunction'<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>parameters: #()<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>receiver: #Oop.<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>aCString _ self cCode: 'myCFunction()'.<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman"><SPAN 
style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN>^ aCString asOop: String<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">It gave me this:<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">:<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">char* aCString;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">int _return_value;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">aCString = myCFunction();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">_return_value = ((int) aCString) - 
4;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">interpreterProxy-&gt;popthenPush(1, 
_return_value);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">But it didn’t work (of course!). As I understand it, this 
assumes that ‘aCString’ points to the first indexable field in an oop and by 
reducing the pointer by 4 it would point to the oop header. Since the c-function 
just returns a plain c-pointer, which has no oop header, the result is that the 
returning oop just points to garbage.<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">So please enlight me on this 
matter!<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">&nbsp;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0pt"><SPAN lang=EN-US 
style="FONT-SIZE: 11pt; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US"><FONT 
face="Times New Roman">Regards Per B. 
Lidebrandt<o:p></o:p></FONT></SPAN></P></FONT></DIV></BODY></HTML>