GameMonkey Script

GameMonkey Script Forums
It is currently Thu Jun 27, 2019 8:42 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Feb 23, 2004 8:16 pm 
Offline

Joined: Wed Feb 18, 2004 3:26 pm
Posts: 6
I'd like to know if there is a way to pass to a function in a script a 32-bit unsigned integer that is for example 0xFFFFFFFF (ARGB color value) without using tables..
Thank you very much.
Claudio


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 25, 2004 9:42 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
I see what you mean and I have played around with some numbers to experiment. Here's what I can say:

o GM currently only supports 'signed int' as a native type. So math on numbers -2b -> +2b are the limits.

o GM could be extended with a user object that handles larger or different types such as 'unsigned int' or 'double float' etc, but this is obviously undesirable as it is less efficient if the type does not fit into the machine word size (and the gmVariable struct)

o GM could be extended by adding new native types. Just as GM has 'int' and 'float' while lua (used to?) only have 'double', GM could also add 'uint' as a native type so you would write code like a = u7; (or similar) where a new syntax could determine the value type.

o Internally, if you don't perform math, and you don't display the number as a string, signed and unsigned ints preserve integrity as they do in C. Perhaps the current GM could be modified to handle hex constants as signed values and NOT truncate as they do at present.

So with that last point, it may be possible to do what you appear to be doing and set a 'color' value or such using a hex constant with a minor modification to the parser. I will look into this. Manually converting your hex values into signed integers just to pass them to bindings would be painful and unnecessarily slow eg. a = uintfunc(0xff, 0xff, 0xff, 0xff); Constant folding should allow a ugly but correct: a = 0xffff << 16 | 0xffff;

At the moment
a = 0xffffffff; // a = 7fffffff (truncated)
a = -1; // a = 0xffffffff
a = 0xffff << 16 | 0xffff; // a = 0xffffffff


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Feb 26, 2004 12:34 pm 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
I have gone ahead and modified the parser to convert hex and binary numbers to unsigned ints thus preserving their precision. In effect it is hex to full signed int due to twos compliment rules. I think people will be happy with this behavior. This change will be in the v1.2x release that is still in testing but you can modify your gmParser.y right now and change the two 'strtol' to 'strtoul'. If you do modify this file, remember to run gmfrontend.bat first to generate new compiler source files as this is not part of the normal project build.

Now:

a = 0xffffffff; // a = 0xffffffff = -1


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Mar 27, 2004 4:19 pm 
Offline

Joined: Wed Feb 18, 2004 3:26 pm
Posts: 6
Thank you for your interest in my problem. I'll download now the new version of Game Monkey Script!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group