First let’s discuss about some of the component we will use
JSContextRef is the equivalent to JSContext in Objective-C, this where the global object reside and other execution state get saved.
Now you have a basic understanding of the framework let’s start coding
When the above code is executed, it should print the following result:
Lets discus what we did
The contextGroup object is the virtual machine and here everything happen.
The globalContext object is the execution environment, the first parameter is the virtual machine object and the second parameter is the class of the root object we pass nullptr to use the default class.
Extending the native function
We will extend the callback function so it will log the parameters passed to it, the callback function should look like this:
The above code represent a small implementation of the filesystem, lets start by describing the classDefinition.
The staticValues array represent the values of the class, the first item is the name the second item is the getter method and the third item is the setter and the fourth item is the attributes, when we want to create a read only property we simply don't provide a setter method.
The callAsConstructor property is our constructor Filesystem_CallAsConstructor, for simplicity our constructor does not check for the validity of the arguments passed to it and assumes everything is OK, the second parameter represent the object constructed by the base class constructor we allocate a new FilesystemPrivate struct and assign it to our object by calling JSObjectSetPrivate.
The setAttributes function takes a pointer to a FilesystemPrivate struct and a path and do some validity checks.
When i executed the above code on my computer i got the following result, "there was a file named file on my desktop"