-
Notifications
You must be signed in to change notification settings - Fork 19
Description
I just had to do some reverse engeneering on the code, because I was very curios:
- How do I obtain "function pointers" from the script. As in:
myFunc{value, function(){ ...callback... }); - How do I store a function away for later use?
- 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...