Skip to content

Question and conversation about Struct types #95

Description

@Redhacker1

I am relatively new here, and I don't know much about language design, edge cases, or design decisions. So I apologize for being ignorant. I am just curious and have a use case (maybe not a very valid one in your eyes), so I wanted to get the ball rolling...

I am currently working on exposing my rendering API to AngelScript, and I didn't come up with a satisfying answer for how to expose uniform data to my scripting API. When I was reading, I did come across in the todo list "Data structures," and I think it is likely almost, if not exactly, what I would be using in an ideal world, and you mention you don't know how useful it would be.

I was wondering if that was one of the things that would end up getting put on the "Probably won't ever implement" chopping block.

If it is not, my thoughts are as follows: "Handles can be safely used in the structures." Sounds like it might cause problems in the use cases structs would actually solve, things like "IPC to a native process, explicit layout in serialization, passing to native memory that expects an arbitrary C-compatible POD-esque structure". I feel like structs should only hold other structures and POD types, Script value, and Application value types that don't/minimally interact with the GC, and that reference types aren't all that useful (may need a flag to set this).

Second, standard handles and/or arrays probably should not be valid; my thoughts are, though, that at compile time a value type/struct, maybe denoted as fixed int ty[5] or similar, would be introduced, which would effectively build 5 int types sequentially in memory (with whatever padding rules are in place to mimic the alignment needed) and offer a generated opIndex() method into those types, similar to what is done for properties.

As for inheriting from other structures, I don't see that as being very useful, since everything is public, and honestly, interfaces sound like the bigger loss there; even then, defining functions that take a structure by reference does not sound too unfortunate.

As for lifetime issues, the only place I see it being an issue is if the struct is in a class; perhaps it could always force a copy in a class by value or box it if the caller is not the owning class's method or the class is not in scope? I don't know what you typically do with references to primitives or the like, but perhaps that same idea could be used to get started, even if not optimal?

I bet some of those are a lot of work, and I am not in any way suggesting this is how it should be done; those are my thoughts on some of what was mentioned.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions