Static extenders confusion

Started by abstauber, Wed 01/08/2018 12:18:56

Previous topic - Next topic

abstauber

After learning about attributes, I am currently implementing them to my modules. Now I have also learned that static extenders are possible since 3.4.

I have a static struct like this, along with its extenders:
Code: ags

struct CustomDialogGui {
  import static void init();
  import static attribute int DialogGuiOptions[];
};
import void prepare(static CustomDialogGui, DialogOptionsRenderingInfo *info);
import void addOption(static CustomDialogGui, int position, int optionNumber, String optionText);
import void getOptionDetails(static CustomDialogGui, DialogOptionsRenderingInfo *info);
import void getRowCount(static CustomDialogGui, int width);


An extender function head looks like this in the .asc file, as it was explained here http://www.adventuregamestudio.co.uk/manual/ags38.htm
Code: ags

void prepare(static CustomDialogGui, DialogOptionsRenderingInfo *info)

Now here's the thing I don't understand.

The attribute extender has to be like declared like a non-static extender. And it even works (wtf)
Code: ags

bool seti_DialogGuiOptions(this CustomDialogGui*, eDialogGuiOptions index,  int value)


So yes, it all works but I don't get why attribute extenders have to be non-static on static structs.

Crimson Wizard

This should work in AGS 3.4.1:
Code: ags

int get_PropertyName(static ClassName)
{
  return 
}

void set_PropertyName(static ClassName, int value)
{
}

abstauber

Sure, but why the exception for the attribute extenders. I just found out that either of these work.
Code: ags

bool seti_DialogGuiOptions(static CustomDialogGui, eDialogGuiOptions index,  int value) {
}

// works too on a static struct, but it should not
bool seti_DialogGuiOptions(this CustomDialogGui*, eDialogGuiOptions index,  int value){
}

Crimson Wizard

#3
That is just an oversight in the ags script implementation.

I do not think it's a good idea to rely on the pointer value inside a static extender, I cannot even tell what it will be, may be just null as well.

EDIT: Don't remember for certain, but it was probably only way to create static attributes before "static" extenders were allowed. If that's correct, then this was left for backwards compatibility.

abstauber

Ah alright, thanks for the clarification! Btw. in your doubleclick module you're using the non-static extender on a static struct - so at one time you might want to fix it.
Code: ags

bool geti_Event(this DoubleClick*, MouseButton mb)

Crimson Wizard

Quote from: abstauber on Wed 01/08/2018 13:42:34
Btw. in your doubleclick module you're using the non-static extender on a static struct - so at one time you might want to fix it.
Code: ags

bool geti_Event(this DoubleClick*, MouseButton mb)


This is done for compatibility with old versions of AGS which did not have static extender support.

SMF spam blocked by CleanTalk