Hybrid Projects | Wrapping
Before we get started into the actual programming and using the engine to understand project development, we need to actually understand our goal. So all we need to do right now is ensure we can build a wrapper that can call C++ code within C code and be able to execute it in Go by calling the SkyLine programming language to load the compiled plugin program.
The idea of having wrappers is to be able to create large projects and easily load them into SkyLine and call the function one after another with them directly. The best part about it will be the factor that your code might not even have to output anything but only return data
Building the C++ Wrapper
In order to build the C code we need to actually build the C++ wrapper which will work like so.
cpp_wrapper.hpp
This may seem like ugly code and horrible for management but right now it is just fine!
Now we have to build our file cpp_wrapper.cpp
Our final step for programming will need to actually now create a .go file that will import the C code and call it using CGO.
Note that we are actually calling the SkyEnvironment or SkyLine Virtual Environment backend code and module file in order to create a function. We do this because the FFI requires the desired function type and exactly what it needs to execute before it can be called and it also needs to return an object when called.
Now we can build a simple makefile called Makefile
Finally we can open the SkyLine REPL and call the function or in a raw script open the code.
And now we have sucessfully written a project that not only used C/C++ but also used Go and could be easily programmed within SkyLine. Loading Plugins may also be easier in the future but for now they will remain like this. It is also important to note that if the function is thrown on a thread then the program and thread will continue to run in the background, this is because before even printing the variable, the backend of SkyLine loads and executes the foreign function interface which in this case would be a function rather than a variable.
Last updated