Ok, thank you!<br><br>David.<br><br><br><div class="gmail_quote">2012/7/2 David T. Lewis <span dir="ltr"><<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>></span><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>
> mmm.... it seems like I don't understand how to try with strings...<br>
> ok, I need something more basic or more information.<br>
> Someone know where can I read about how to try strings en SLang?<br>
><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 "hello world" 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 "hello world",<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 "hello world"<br>
from the C string into the data area of the new String object, then<br>
you will have a 'hello world' 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 'hello world'.<br>
<div class="im"><br>
><br>
> Are differences between how to try strings on numeric primitives and named<br>
> primitives? Because I'm doing proves with numeric primitives.<br>
><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>
'hello world', 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>
<br>
Dave<br>
<br>
</blockquote></div><br>