newLISP Fan Club

Forum => newLISP in the real world => Topic started by: ale870 on January 04, 2009, 06:15:27 AM

Title: How to map newLisp datatypes in C
Post by: ale870 on January 04, 2009, 06:15:27 AM
Hello,

I'm using the following code to "map" (callback fashion) some PureBasic functions in newLisp.



For example:


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...


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!
Title:
Post by: pjot on January 04, 2009, 07:16:23 AM
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
Title:
Post by: ale870 on January 04, 2009, 07:18:34 AM
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!
Title:
Post by: ale870 on January 04, 2009, 07:28:00 AM
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!!!
Title:
Post by: pjot on January 04, 2009, 07:37:47 AM
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
Title:
Post by: ale870 on January 04, 2009, 07:39:17 AM
Now I have problems in returning parameter :-(



It seems double does not work. I will try float.
Title:
Post by: pjot on January 05, 2009, 07:57:45 AM
Any results?



Are you using 64bit or 32bit of newLisp?