mattn / anko

Scriptable interpreter written in golang

Home Page:http://play-anko.appspot.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't import in embedded scripts

c4s4 opened this issue · comments

Let's take this Go code:

package main

import (
	"github.com/mattn/anko/core"
	"github.com/mattn/anko/vm"
)

func main() {
	var env = vm.NewEnv()
	core.Import(env)
	_, err := env.Execute(`import("os")`)
	if err != nil {
		panic(err)
	}
}

This doesn't work:

$ go run test.go 
panic: undefined symbol 'import'

goroutine 1 [running]:
main.main()
	/home/casa/dsk/test.go:13 +0x80
exit status 2

Import has moved into packages.

package main

import (
	"fmt"

	"github.com/mattn/anko/packages"
	"github.com/mattn/anko/vm"
)

func main() {
	var env = vm.NewEnv()
	packages.DefineImport(env)
	_, err := env.Execute(`import("os")`)
	if err != nil {
		panic(err)
	}

	fmt.Println("GTG")
}

OK thanks for this quick feedback.