GMWolf
aka fel666
I am a firm beleiver in reflective code when creating libraries, especially in GM where other solutions may not be availbable.
However, there is not much opportunity for reflective codde to be used effectivly at the moment as GM offers very little support for adding meta data.
That is why i suggest you include new syntax to add such information to scripts.
I propose two forms of syntax:
I will assume suggestion 1 for the remainder of this post, but the second suggestion would work in the exact same way.
In any script, you could write @something to add data to the script. Any number of such lines could be inserted into a script.
When calling script_get_annotations(script), it would return an array filled with each of the annotations as strings.
the following:
would return the array ["global", "object oPlayer"] when the script_get_annotations() script is called.
It would then be up to the developer to know what to do with this data.
This would open up many possibilities to create far more powerful libraries. example use could be to define what script should run when a certain script is called by an object (@polymorph scr_parent object) , to explicitly define the return type of a script (@returns string), or globally binding scripts to events (@event ev_mouse ev_left_press). The possibilities are infinite.
This could even be used by future GM functions to implement more complex behaviour that would have previously needed the user to run arbitatry code at game startup.
This could even be expanded to objects, in order to have metadata about objects too. (I have in the past seen code that would simply use variables, create the object, then destroy it again after having extracted the variable.)
I believe that adding such functionality will drastically improve the quality of libraries, as developers will be able to offer much more complex behaviour with a very simple data driven approach. This would greatly benefit GM as a product as more the language will become far more mature as a result.
However, there is not much opportunity for reflective codde to be used effectivly at the moment as GM offers very little support for adding meta data.
That is why i suggest you include new syntax to add such information to scripts.
I propose two forms of syntax:
Code:
//suggestion 1
@something here
script_get_annotations(script)
//suggestion 2
#meta something here
sccript_get_metadata(script)
In any script, you could write @something to add data to the script. Any number of such lines could be inserted into a script.
When calling script_get_annotations(script), it would return an array filled with each of the annotations as strings.
the following:
Code:
@global
@object oPlayer
It would then be up to the developer to know what to do with this data.
This would open up many possibilities to create far more powerful libraries. example use could be to define what script should run when a certain script is called by an object (@polymorph scr_parent object) , to explicitly define the return type of a script (@returns string), or globally binding scripts to events (@event ev_mouse ev_left_press). The possibilities are infinite.
This could even be used by future GM functions to implement more complex behaviour that would have previously needed the user to run arbitatry code at game startup.
This could even be expanded to objects, in order to have metadata about objects too. (I have in the past seen code that would simply use variables, create the object, then destroy it again after having extracted the variable.)
I believe that adding such functionality will drastically improve the quality of libraries, as developers will be able to offer much more complex behaviour with a very simple data driven approach. This would greatly benefit GM as a product as more the language will become far more mature as a result.
Last edited: