JBenda / inkcpp

Inkle Ink C++ Runtime with JSON>Binary Compiler
MIT License
70 stars 13 forks source link

Get INK Global Variables from C++ #10

Closed JBenda closed 3 years ago

JBenda commented 3 years ago

Enables reading and writing of INK global variables from C++ code.

Use template function in class globals to access them.

class {
    // @brief access global variable from ink story
    // @param name name of variable (as defined in Ink Script)
    // @return nullptr if there is no such variable
    // @return pointer to variable
    template<typename T>
    T* get_global(const char* name);
}
JBenda commented 3 years ago

The getInt, getStr etc. functions are kind of ugly, but I can't see a way around when we would keep it an interface.

JBenda commented 3 years ago

The test case run without error ^^ But you need to compile the GlobalStory.ink, because they are now InkBin allowed in the repository, maybe with some cmake magic we can build it when running test.

brwarner commented 3 years ago

As part of my work getting the ink-proof test suite to work, I'm going to add have the GitHub Actions download the OS appropriate version of the inklecate compiler. The goal is to have cmake compile any ink files it finds as part of running the tests suite (including our unit tests).

JBenda commented 3 years ago

Sweet :+1:

brwarner commented 3 years ago

Somehow I closed this?

Oh, it was because I deleted the platform branch after merging your other PR....? Can you merge master in your GetGlobals branch and submit a new PR into master?

Sorry, I'm new to managing open-source projects with multiple contributors so I'm still figuring this stuff out.