Skip to content

About Core::* types #59

@IngwiePhoenix

Description

@IngwiePhoenix

I just had to do some reverse engeneering on the code, because I was very curios:

  1. How do I obtain "function pointers" from the script. As in: myFunc{value, function(){ ...callback... });
  2. How do I store a function away for later use?
  3. How can I obtain other types as permanent values?

Originally, I wondered about that with V8's C++ api in mind, where you have Local<...> and Persistant<...> types. The classes to fill into the template are either String, Number, Object, Function or any other valid JS type that is found under the v8 Namespace.

And secondarily, I wanted to learn more about the VM behind ObjectScript. Because - I wanted to know how data is saved and represented there. Boy I was not expecting what I found:

class Core {
    struct Value { ... }
    struct GCFunctionValue : public GCValue {...}
    struct GC{other type name}: public GCValue {...}
    class String { ... }
    class Buffer { ... }
}

As the class title suggested, those types were ment to be used internally. But - why?

As I asked in my previous questions, it would be highly usable to convert a type from the VM into something that C++ land understands. Turning something like this:

var callbackData = {
    beforeAction: function(){ ... },
    afterAction:  function(){ ... }
};

into something like this:

class OS::Value {
public:
    ...
    operator[](const OS_CHAR key);
    operator[](...);
    ...
    OS_EValueType type();
    void pushValue(OS*);
};

// In a function
OS::Value callbackData = os->getValue(...);
if(callbackData.isset("beforeAction")) {
    callbackData["beforeAction"]->pushValue(os);
    ...
    os->call(...);
}

For the case of embedding OS into a C++ application, it would make things very, very easy to be able to keep a refference to a function passed to a function and re-use it later. I have not come very far in my studdy yet, so I have to ask you for the implementation. But it could make things quite easy for embedding.

What is your opinion on this? Do you think it's do-able? Please let me know! I am kinda stuck with my previous issue at this moment...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions