How to map newLisp datatypes in C

Q&A's, tips, howto's
Locked
ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

How to map newLisp datatypes in C

Post 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!
--

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post 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

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post 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!
--

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post 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!!!
--

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post 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

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

Now I have problems in returning parameter :-(

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

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Any results?

Are you using 64bit or 32bit of newLisp?

Locked