Register
BEdit»Forums»include?
Benjamin Pedersen
37 posts

Mathematician

include?
3 weeks, 3 days ago Edited by Benjamin Pedersen on May 19, 2021, 2:03 p.m. Reason: Initial post
I am working with two related formats. They share an enum. I suspect some include feature is on the todo. Is it coming soon?
Jens
44 posts / 1 project
include?
2 weeks ago
Include (or some variant of it) is very much on the todo-list!

I don't think a C-preprocessor "copy-paste"-styled include would be the best though. Say you have:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// In formatA.bet
struct Header
{
    string(4) magic;
    u(4) version;
    ...
};

struct File
{
    Header header;
    ...
};

layout File;


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// In composite.bet

include("formatA.bet");
include("formatB.bet"); // Also defines type File and does layout

struct CompositeFile
{
    // What type is what here?
    File fileOfTypeA;
    File fileOfTypeB;
};

layout CompositeFile; // Is this layout done after the included files? Is the included files not doing layout?


Include is also a feature that is needed before some of the incoming major addition to the layout language, so it's somewhat high on the todo list.


I'm currently leaning on a more Python like include, like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
include(A="formatA.bet");
include("formatB.bet");

// or maybe even:

include(A = "formatA.bet", "formatB.bet")

struct CompositeFile
{
    // Dot is getting very overloaded so might be something like : instead...
    A.File fileA;
    formatB.File fileB;
};

layout CompositeFile;


and only run layout commands if it's the "main" file being executed.

This is currently very much in idea phase so any suggestions would be highly appreciated.
Benjamin Pedersen
37 posts

Mathematician

include?
2 weeks ago
Makes sense, and "Import" might honestly be a better keyword to differentiate it from preprocessor-include. I think I used "include" because of the syntax being very C-like.