<br><br><div class="gmail_quote">On Mon, Jul 2, 2012 at 6:15 AM, David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Sun, Jul 01, 2012 at 06:01:23PM -0300, David Leonhardt wrote:<br>
&gt; mmm.... it seems like I don&#39;t understand how to try with strings...<br>
&gt; ok, I need something more basic or more information.<br>
&gt; Someone know where can I read about how to try strings en SLang?<br>
&gt;<br>
<br>
</div>When you create a new String object to return from your primitive,<br>
that object is part of the object memory managed by the VM. If you<br>
have the string &quot;hello world&quot; in some C code for your primitive,<br>
that string is not part of the object memory managed by the VM.<br>
It is just a null-terminated array of characters somewhere in the<br>
C program, allocated in memory somewhere outside of the Squeak<br>
object memory. This means that if you want your primitive to return<br>
a string, you should have your primitive create a new object of<br>
type String, copy the data from the C string into the data portion<br>
of the String object, and return that object as the result of the<br>
primitive.<br>
<br>
Thus in order for a primitive to answer the string &quot;hello world&quot;,<br>
the primitive should create a new instance of a String object with<br>
length 11. This object will (inside the object memory) have a header<br>
that indicates the type of object, and enough data space to hold<br>
11 bytes of char data from a C string. If you copy &quot;hello world&quot;<br>
from the C string into the data area of the new String object, then<br>
you will have a &#39;hello world&#39; String object in the Smalltalk object<br>
memory. You can put that object on the stack to return it as the<br>
result of a primitive call, and the result will be a primitive<br>
that answers the string &#39;hello world&#39;.<br>
<div class="im"><br></div></blockquote><div><br>Excellent explanations. <br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">

&gt;<br>
&gt; Are differences between how to try strings on numeric primitives and named<br>
&gt; primitives? Because I&#39;m doing proves with numeric primitives.<br>
&gt;<br>
<br>
</div>No, there is no difference between numeric primitives and named<br>
primitives. These are just two different ways of calling a primitive<br>
from the image. If you write a primitive to answer the string<br>
&#39;hello world&#39;, you will write it the same way regardless of whether<br>
it is a numbered primitive or a named primitive. But in general you<br>
should use named primitives whenever possible.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br>I wrote: <a href="http://marianopeck.wordpress.com/2011/06/03/primitives-pragmas-literals-and-their-relation-to-compiledmethods/">http://marianopeck.wordpress.com/2011/06/03/primitives-pragmas-literals-and-their-relation-to-compiledmethods/</a><br>
<a href="http://marianopeck.wordpress.com/2011/07/06/named-primitives/">http://marianopeck.wordpress.com/2011/07/06/named-primitives/</a><br><br>maybe it helps with something. <br><br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="HOEnZb"><div class="h5">
Dave<br>
<br>
_______________________________________________<br>
VM-beginners mailing list<br>
<a href="mailto:VM-beginners@lists.squeakfoundation.org">VM-beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br><br>