Skip to content

Add import function for external libraries#300

Open
FlutterTal wants to merge 2 commits intoalbertodemichelis:masterfrom
FlutterTal:import_func
Open

Add import function for external libraries#300
FlutterTal wants to merge 2 commits intoalbertodemichelis:masterfrom
FlutterTal:import_func

Conversation

@FlutterTal
Copy link

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.

@hakanrw
Copy link

hakanrw commented Aug 19, 2025

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?

@hakanrw
Copy link

hakanrw commented Aug 19, 2025

@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 :)

@FlutterTal
Copy link
Author

@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 ^^

@hakanrw
Copy link

hakanrw commented Aug 19, 2025

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants