File: plugin.go

package info (click to toggle)
golang-github-evilsocket-islazy 1.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 292 kB
  • sloc: javascript: 8; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 722 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main

import (
	"fmt"

	"github.com/evilsocket/islazy/plugin"
)

func main() {
	// define some functions
	plugin.Defines = map[string]interface{}{
		"log": func(s string) interface{} {
			fmt.Println(s)
			return nil
		},
	}

	// load the plugin
	plug, err := plugin.Load("examples/plugin.js")
	if err != nil {
		fmt.Printf("%v\n", err)
		return
	}

	// call methods
	methods := plug.Methods()
	for _, m := range methods {
		ret, err := plug.Call(m)
		if err != nil {
			fmt.Printf("error while calling %s function: %v\n", m, err)
		} else if ret != nil {
			fmt.Printf("plugin.%s -> %v\n", m, ret)
		}

	}

	// get variables
	obj, err := plug.GetObject("Text")
	fmt.Printf("plugin.Text = '%s'\n", obj.(string))
}