-
-
Notifications
You must be signed in to change notification settings - Fork 20.9k
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
Add Structs to GDscript #90356
base: master
Are you sure you want to change the base?
Add Structs to GDscript #90356
Conversation
a2483fd
to
7abff93
Compare
dc6625d
to
d906d86
Compare
case GDScriptParser::ClassNode::Member::STRUCT: { | ||
if (!member.m_struct) { | ||
break; | ||
} | ||
const GDScriptParser::StructNode &struct_node = *member.m_struct; | ||
StructInfo struct_info = StructInfo(struct_node.identifier->name, struct_node.members.size()); | ||
for (int j = 0; j < struct_info.count; j++) { | ||
const GDScriptParser::VariableNode *struct_member = struct_node.members[j]; | ||
Variant default_value = struct_member->initializer ? struct_member->initializer->reduced_value : Variant(); // TODO: need better logic here. | ||
struct_info.set(j, | ||
struct_member->identifier->name, | ||
struct_member->datatype.builtin_type, | ||
struct_member->datatype.native_type, | ||
nullptr, | ||
default_value); | ||
//TODO: does not yet support nested structs. | ||
} | ||
p_script->structs.insert(struct_info.name, struct_info); | ||
} break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dalexeev @vnen Whenever either of you have time, I'd love some help on how I should be handling struct defaults. The current approach here is to store the reduced value of the initializer expression. The major problem with this approach is that It does not work for reference types like Dictionary
or Object
because every default struct will have a reference to the same value of the reference type, instead of a fresh copy.
I think the solution is to compile something like an implicit_new
function and then call it to obtain a fresh default struct. I'm having trouble implementing that approach however, because I'm not quite sure how implicit_new
functions are compiled. It seems like it occurs in _parse_function
, but that seems to create the constructor for the whole class, whereas I just want the constructor for a struct within the class. Any tips?
d906d86
to
8c7b732
Compare
8c7b732
to
6fb6053
Compare
Should a struct be exported via
|
86c68a9
to
35d7383
Compare
Depends on #82198. That PR implements the new Struct type based on Reduz's proposal godotengine/godot-proposals#7329 in core, but not in GDScript. This PR implements them in GDScript. This PR includes the commit of the dependent PR, but I will drop it once #82198 is merged.
It is still very much a work in progress and currently not a stable branch.