Add import function for external libraries#300
Add import function for external libraries#300FlutterTal wants to merge 2 commits intoalbertodemichelis:masterfrom
Conversation
|
I like this functionality, I was actually going to write a Lua-style native module loading myself, but I came across your solution 😄 @albertodemichelis I think this would be a good feature for Squirrel 3.3. What are your thoughts on it? |
|
@FlutterTal I love it overall, but is there a reason you picked the strategy to pass an API struct with function pointers instead of just depending on the public API and passing the VM struct instead? The dynamic loader would take care of relocations against libsquirrel for runtime dlsym/dlopen as well, I think Windows should support that too. That'd heavily simplify your patch. Just curious about your thoughts on this :) |
|
@hakanrw I'm just using what I know. Because AFAIK I didn't find any other way to link and import code to a Squirrel script, especially if the code is from a C++ library As for the Windows support, I agree with you here. But thing is I'm on Linux, and I have no idea how to use the Windows API thing On those things, if you wanna contribute, I'm open for it ^^ |
|
@FlutterTal Thanks for your swift response! I will have a look at it this week and try implementing the approach I've explained. That should cut down the patch by ~350 lines, give or take. It would be a minimal but still powerful solution akin to Lua's, and I predict it will simplify maintenance going forward. Have a great day! |
Inspired by Sqrat, I feel like this is a very useful functionality to import external libraries to the main Squirrel language. You can use
import(module)(without the extension) to import the library, and optionally push it to a table.