TheExDeus
|
|
Posted on: March 26, 2011, 05:34:22 pm |
|
|
Joined: Apr 2008
Posts: 1860
|
So I am using script indexes which I later call to add easy modularity to my program. So to add an element I just write something like this:
scr_element_add(spr_r,draw_resistor,"R_{index}",get_resistor_bbox,"1 /Ohm",0,"resistor rezistors R","R",0); scr_element_add(spr_vsrc,draw_vsrc,"U_{index}",get_capacitor_bbox,"1V",0,"vsrc sprieguma voltage avots","vsrc",0); scr_element_add(spr_isrc,draw_isrc,"I_{index}",get_capacitor_bbox,"1A",0,"isrc strava current avots","isrc",0); draw_vsrc, for example, is the script index. Previously I didn't know GM returned script indexes when you type its name without arguments and parenthesis and previously I just used some via ass way by looping trough all scripts and finding the correct one by name. Anyway, I have something like this in the draw event:
script_execute(draw_script,x,y,element_rotation,0,color,color2); So basically to add a new element I just create a new draw script and not a new object or something like that. So the question basically is if I can do this (or will be able to) in Enigma? In C++ I can get a function pointer and then using that to execute the script/function, but a function like script_execute is not needed. So in C++ I could write something like this:
draw_script(x,y,element_rotation,0,color,color2); Will this be the case in Enigma or will there actually be script_execute function? Right now typing a script name without parenthesis just shows an error (that the script is not declared in this scope).
|
|
|
Logged
|
|
|
|
RetroX
|
|
Reply #1 Posted on: March 26, 2011, 06:16:52 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
There will be script_execute, but it won't likely be what you expect. In ENIGMA, script names refer to an integer of that's script ID. ENIGMA sets the global variables argument0-(N-1) and the script uses them. If you want function pointers, use actual functions, not scripts. And when you do, take into consideration what you're trying to accomplish - do you really need them? On a random note, the GCC 4.6 will likely come out within the next three days, and it supports lambda functions with the std=gnu++0x flag.
|
|
|
Logged
|
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)Why do all the pro-Microsoft people have troll avatars?
|
|
|
Rusky
|
|
Reply #2 Posted on: March 26, 2011, 07:48:56 pm |
|
|
Joined: Feb 2008
Posts: 954
|
GCC 4.6 came out yesterday (yay!): http://ftp.gnu.org/gnu/gcc/gcc-4.6.0/, but yes lambda functions will be quite nice. script_execute in Enigma works just like GM, doesn't it? It takes a script id, which works the same as well, along with some arguments, and calls the script with them. Also, are argument{n} really global? O_o
|
|
|
Logged
|
|
|
|
RetroX
|
|
Reply #3 Posted on: March 26, 2011, 10:19:28 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
Ah, didn't know that it came out yesterday. Hasn't reached the Arch repositories yet. Apparently, it was flagged today, so, it'll probably be updated by tomorrow afternoon.
|
|
« Last Edit: March 26, 2011, 10:22:11 pm by RetroX »
|
Logged
|
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)Why do all the pro-Microsoft people have troll avatars?
|
|
|
TheExDeus
|
|
Reply #4 Posted on: March 27, 2011, 05:02:08 am |
|
|
Joined: Apr 2008
Posts: 1860
|
script_execute in Enigma works just like GM, doesn't it? It takes a script id, which works the same as well, along with some arguments, and calls the script with them. There is no script execute in Enigma. That is why I am asking how is this going to work (if ever). If it works exactly like in GM then I don't have any need to change anything and I have no problem with that implementation. If you want function pointers, use actual functions, not scripts. But aren't scripts just custom functions? Calling a script is just calling a function. Every script is declared for each object that uses it, which is bad, but it still is a function. So I thought I might as well get the pointer to it and then call just like normal.
|
|
|
Logged
|
|
|
|
|
TheExDeus
|
|
Reply #6 Posted on: March 27, 2011, 10:40:09 am |
|
|
Joined: Apr 2008
Posts: 1860
|
argument0-N are global vars, not passed as parameters. You are sure? Looking at the code it seems to just call it like a function. So this is how the script looks after parsing: variant enigma::OBJ_obj_0::scr_test(variant argument0, variant argument1, variant argument2) { var test, something; test = argument0; something = test + argument1; return test + something; ; return 0; } And this is the create event: variant enigma::OBJ_obj_0::myevent_create() { enigma::temp_event_scope ENIGMA_PUSH_ITERATOR_AND_VALIDATE(this); b = scr_test(5, 1); ; return 0; } So it seems that the variables are not global, but used just like in normal functions. The only bug I see is that it declares one argument too many.
|
|
|
Logged
|
|
|
|
Josh @ Dreamland
|
|
Reply #7 Posted on: March 28, 2011, 01:36:27 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Currently, ENIGMA defines scripts as the actual functions inside each object scope. To correct this, the compiler must export the following:
enum { script0 = 0, script1 = 1, // ... }; //... variant SCR_script0(/*...*/) { //... return 0; } variant SCR_script1(/*...*/) { //... return 0; } //...
#define script0(x...) SCR_script0(x) #define script1(x...) SCR_script1(x)
variant execute_script(int scr, variant arg0 = 0 /* ... (all of these will be defined and defaulted) */) { switch (scr) { case 0: return SCR_script0(/* ... (The same number of parameters as the script max will be used) */); case 1: return SCR_script1(/* ... */); } }
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
TheExDeus
|
|
Reply #8 Posted on: March 28, 2011, 02:42:44 pm |
|
|
Joined: Apr 2008
Posts: 1860
|
Currently, ENIGMA defines scripts as the actual functions inside each object scope. To correct this, the compiler must export the following: Then why doesn't it? If this works and surfaces are implemented (I know, you are probably sick of people asking for surfaces) then I could actually run the program in Enigma. I would develop the rest of the missing functions myself.
|
|
|
Logged
|
|
|
|
|
|