KelvinShadewing / brux-gdk

Free runtime and development kit using SDL and Squirrel
GNU Affero General Public License v3.0
40 stars 20 forks source link

Squirrel Modules - Sqrat Import #10

Closed joseph-montanez closed 7 years ago

joseph-montanez commented 7 years ago

I've been working on integrating Chipmunk 2D Physics and I have been stuck with littering core methods and files as there is no other way to integrate additional functionality from external libraries.

I've run into several issues but the biggest is that fact that if I want to add more features I have no choice but to keep modifying the core. This is a problem because I know everything I'd want will not be accepted. Plus this adds yet one more dependancy when wanting to work on XYG Studio.

Sqrat makes integrating Squirrel way easier, and one feature is has it to load modules inside a squirrel script.

Integration is really easy from the core perspective:

#include "sqratimport.h"

sqrat_register_importlib(v);

Then when I build my Chipmunk to Squirrel integration, in my Squirrel script I'd load the .dll / .so via

::import("Chipmunk");

Sqrat has a lot of other great features, and I've been reading the source code to understand how to integrate namespaces and classes, but it already has those features that are much easier to maintain.

If this sounds okay I can go ahead and make a pull request with the integration.

joseph-montanez commented 7 years ago

So I was wracking my brains on why import() was not working in the sqrat import code I have and found out that there is already sqImport using import(). Another benefit of using sqrat import is that is can import regular Squirrel scripts, compiled Squirrel scripts and DLL/SO/DyLib extensions. If you want to move forward with this it should replace spImport since its a more feature rich type of import.

I did have to edit some of the sqrat source code to add in MacOS compatibility so this will most likely need to be embedded with the XYG Studio source code.

KelvinShadewing commented 7 years ago

I'm probably going to remove import() and just have the library all be loaded, because apart from constants and a few functions that are easier to implement in Squirrel, I think most of it is going to end up inside the runtime itself.

Shared objects would be useful, though the original plan was to have everything inside the runtime already so people porting it to their own platform wouldn't have to worry about building a bunch of other things to, but maybe that isn't possible. I suppose leaving the DLL option open and just trying to add in as much as I can as I go would give the best of both worlds.

KelvinShadewing commented 7 years ago

Oh, I've also been looking at Chipmunk Physics, and it looks pretty cool. It's under MIT license, so given what I've looked up, it could be put directly into the runtime.