Use characters as longs
stevenmess2004
Posts: 1,102
Is it possible to use a series of byte as a long? I have tried it but with no luck so far.
If I have a prototype
PUB callObject(objectName,methodName,arg)
is there some way of doing this
return callObject("test","run",0)
I can just use numbers but if I can use words it will mean less mistakes.
Does anyone have any ideas?
Steven
If I have a prototype
PUB callObject(objectName,methodName,arg)
is there some way of doing this
return callObject("test","run",0)
I can just use numbers but if I can use words it will mean less mistakes.
Does anyone have any ideas?
Steven
Comments
There really isn't a simple, natural-looking constructor in Spin for concatenating bytes into a long. As an alternative you could use string, but that creates an additional level of indirection that you may not want.
-Phil
Steven
-Phil
Thanks Phil
Steven
-Phil
Steven
CON
#0, test, run, thing1, thing2
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
With the DOL, you could still create otherwise-null objects that just have constants in them and declare those objects in both caller and callee programs. Referring to a single definition file is a Good Thing that eliminates all kinds of maintenance headaches. Granted, the objectname#const notation is a bit wordy.
-Phil
Less so if you set such constant files to be referred to by a single letter such as "c" or "g" in the OBJ statement.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com
Play Defender - Propeller version of the classic game
Prop Room Robotics - my web store for Roomba spare parts in the UK
Whatever DOL does, constants are resolved at compile time, there is no overhead.
When you use "ABC" as LONGs or WORDs you are in the bad habbit of some languages of the "everything is a string" kind, which is acceptable for GB memories but not for the Propeller.
Note that that the LONG containing "ABC" has to be alloctated somewhere; the storrage situation will be equivalent to:
In C, they look like this int32 = "ABcd". They only occupy 4 (2) bytes (no terminating zero). They are handy for signatures.
That doesn't work in Spin.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
@Phil and CardboardGuru - I thought you had to have a method in a *.spin file? I'll check. If you don't then that's what I'll do.
this works:
CON
· name = "t"<<24 + "e"<<16 + "s"<<8 + "t"
and you then use it like
callObject(objectConstants#name,...)
regards peter
You do. So just end the file with:
PUB dummy
You don't have to call it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com
Play Defender - Propeller version of the classic game
Prop Room Robotics - my web store for Roomba spare parts in the UK
It is very clear to most persons here (to some earlier, to some later) what stevenmess intends to do: He wants to have a "speaking" parametrization. This is quite common in "everything is a string"- languages, as TK, Perl, PHP,...
In SPIN the construct "ABC" does not denote a string (as there is no datastructor or "strings" in SPIN), rather it can be used in CONSTANT context as a specific preset.
statically allocates "A", "B", "C", 0 to the memory and yields a pointer to it.
also allocates memory (three bytes).
The main objective of stevenmess - to have "speaking parameters" - can not be obtained in this way, as "ABC" is just not a valid element as a parameter.
If it were, it would take also take the same amount of additional storage as in my second example.
Languages that allow strings and word constants sometimes distinguish this be using ".." for strings and '...' for alphanumeric contents.
So please use constants as recomended many times here!