srijan-paul / snap

An embeddable scripting language inspired by Lua.

Home Page:https://injuly.in

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement user-side module loading and module caching

srijan-paul opened this issue · comments

Currently, only standard library modules can be loaded and cached.
We want to be able to load modules from anywhere within the current directory.

Note:

  1. Calling import returns a table.
  2. There are 2 kinds of modules
    2.1. Native modules written in C++ and exposed via the Vyse API.
    2.2. Modules written in Vyse (more common).
  3. Native modules are a bit harder to deal with, because we have to make sure we keep a handle to the shared library around in memory. Loading the same module multiples must not create new handles, that counts as a memory leaks. Whether the handles should be garbage collected when the contents of a module die is still undecided.
  4. Vyse modules are easier, we need to read some text from a file somewhere in the filesystem and the VM does the rest.

I feel further brainstorming on this topic will help come up with more concrete ideas (especially with 3).
This could be done in 2 PRs, one that loads vyse modules and one that loads native ones.

Closed thanks to #20 :D