Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing builtin, attribute and static in ScriptKeywords #217

Open
ericoporto opened this issue Apr 21, 2023 · 3 comments
Open

missing builtin, attribute and static in ScriptKeywords #217

ericoporto opened this issue Apr 21, 2023 · 3 comments

Comments

@ericoporto
Copy link
Member

Some specifiers like writeonly and others are described in ScriptKeywords, but attribute, builtin and static are missing there. I added some notes below

attribute

The attribute keyword can be used like

struct A {
  import attribute int value;
  import int get_value(); // $AUTOCOMPLETEIGNORE$
  import void set_value(int value); // $AUTOCOMPLETEIGNORE$
};

builtin

We use builtin to prevent a managed struct to be created without a factory method or other method, that is usually in the Engine or in a Plugin.

IDEA I noticed it would be nice to be able to restrict to only factory method when it's outside the script unit (not in the asc/ash pair that contains the struct), because them we could also use this in script modules.

static

used together with things that can be imported in a struct, to specify you can call it without requiring an instance of the object. You can restrict it to appear only in the static variant of the auto-complete with a special comment.

managed struct B {
  import static B* Create(); // $AUTOCOMPLETESTATICONLY$
  int magic;
}
@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Apr 21, 2023

IDEA I noticed it would be nice to be able to restrict to only factory method when it's outside the script unit (not in the asc/ash pair that contains the struct), because them we could also use this in script modules.

AGS currently does not have a strict concept of "script unit", in theory any header (and even other src) may be included into any script. This is especially going to be a problem with standalone compiler, which does not know anything about the project structure and ash/asc pairing.

Restricting to factory methods could be done using private constructors, if AGS supported constructors.

@ericoporto
Copy link
Member Author

Ah, ok. I noticed this when testing the PR on pointers in managed structs, that I wanted a factory Create() static method in my managed struct, as the only way to create them, to make sure the fields that were pointers to other structs to also be initialized. This saves me from checking for null when using it's members.

@ivan-mogilko
Copy link
Contributor

This saves me from checking for null when using it's members.

Perhaps you could mark them as writeprotected, and assume they are always set? This may cause module user to get errors if they use new, but they will remember eventually, and there will be less checks in code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants