[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
GameMonkey Script • View topic - new/delete operators within script

GameMonkey Script

GameMonkey Script Forums
It is currently Sat Sep 26, 2020 10:27 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Nov 13, 2011 1:38 pm 
Offline

Joined: Mon Feb 12, 2007 12:17 am
Posts: 13
Hello,

Currently, whenever a "type" (Such as vector3, player, etc) is declared to the GM VM, I take the type integer that's returned, and feed into a hashmap that returns my type information in the engine. This is also then "executed" in the VM as "global typename = typeid;".

I then create a function called "new", which takes this typeid. When it is called, it creates and returns an object, based upon the lookup of that typeid.

I was wondering if anyone has actually created new and delete operators, so instead of this:

pl = new(Player);

I could do

pl = new Player;

Thanks in advance!


Top
 Profile  
Reply with quote  
PostPosted: Sat Nov 26, 2011 1:37 pm 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
I havn't tried, but it would be possible with a bit of work.

Why not just do

pl = Player();

or even:

pl = Player.New();


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 05, 2011 12:19 pm 
Offline

Joined: Fri Jun 19, 2009 12:39 pm
Posts: 31


Top
 Profile  
Reply with quote  
PostPosted: Tue Dec 06, 2011 12:43 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
Just a quick comment on this...

Although the described work around is reasonable eg. pl = Player(); It still requires binding of a same named function to return the new instance. Since types could be created dynamically from script or native code, there is justification to implement something like operator new in future, as a standard way to create a new instance. (It happens to be in our design notes for a possible future version of GM.)


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