Page 1 of 1

How to map newLisp datatypes in C

Posted: Sun Jan 04, 2009 2:15 pm
by ale870
Hello,
I'm using the following code to "map" (callback fashion) some PureBasic functions in newLisp.

For example:

Code: Select all

Procedure.s d4CreateCube(argSize.s, argPosX.s, argPosY.s, argPosZ.s)
  ... do something ...
EndProcedure

(set 'create-cube dummy1)
(cpymem (pack {ld} 265) (first (dump create-cube)) 4)
(cpymem (pack {ld} @create-cubeADDR) (+ (first (dump create-cube)) 12) 4)
(cpymem (pack {ld} {create-cube}) (+ (first (dump create-cube)) 8)  4)
My problem is I cannot realize a similar thing passing FLOAT as function parameters (d4CreateCube).

Using string or LONG everything works, but with float... my program crashes.
I want to make a PB function as...

Code: Select all

Procedure.s d4CreateCube(argSize.f, argPosX.f, argPosY.f, argPosZ.f)
  ... do something ...
EndProcedure
Even if I talk about PureBasic I can get examples/hints with standard C types :-)

Thank you!

Thank you!

Posted: Sun Jan 04, 2009 3:16 pm
by pjot
Hi,

newLisp makes a distinction between DOUBLE and FLOAT.

By default newLisp uses DOUBLE internally.

If you need FLOAT in newLisp make sure to cast your value using the (flt) statement.

Hope this helps....
Peter

Posted: Sun Jan 04, 2009 3:18 pm
by ale870
Thank you for your info!
I will try to work with double, since I want to avoid the users need to make explicit conversion using (float) function.

Thank you.
I will make a post about the results of my tests!

Posted: Sun Jan 04, 2009 3:28 pm
by ale870
Well, I confirm you are right!
I used double as parameters, and I use "strD()" to convert received double values as string.

Thank you for your help!!!

Posted: Sun Jan 04, 2009 3:37 pm
by pjot
Good!

BTW, don't get confused with the newLisp (float) statement, in fact this will convert a string or a number to float syntax, but in reality it is a double of 8 bytes.

The (flt) statement however converts a number to a C float which comprises 4 bytes.

Regards

Posted: Sun Jan 04, 2009 3:39 pm
by ale870
Now I have problems in returning parameter :-(

It seems double does not work. I will try float.

Posted: Mon Jan 05, 2009 3:57 pm
by pjot
Any results?

Are you using 64bit or 32bit of newLisp?