Skip to content

Any idea on how to import a module when embedded within Go? #306

Answered by SolarLune
SolarLune asked this question in Q&A
Discussion options

You must be logged in to vote

OK, I see, I need to create a new local importer with the source directory I'm looking for and then call Importer.Import() with a context and the name of the modules I'm interested in importing. The following works for me:

	// Instantiate script importer with imported libraries
	if scriptImporter == nil {

		globalNames := []string{}
		sourceDir := "assets/entities/libraries"

		// builtins.Builtins() is built-ins that are normally automatically made available in an explicitly run Eval() function call (len(), keys(), etc.).
		for k := range builtins.Builtins() {
			globalNames = append(globalNames, k)
		}

		// Create the script importer; the source directory is the location of the source…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by SolarLune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant