diff options
author | Maran <maran.hidskes@gmail.com> | 2014-06-04 18:19:50 +0800 |
---|---|---|
committer | Maran <maran.hidskes@gmail.com> | 2014-06-04 18:19:50 +0800 |
commit | 307fe4a3cd4ff2d3910ed992e6e98a7cd3ca6f87 (patch) | |
tree | 8c42de0b04c8990bd0010563ce650a12c11e1a74 /ethereum | |
parent | 3755616a2912f47a963d4ecc781bddd4229fe290 (diff) | |
download | go-tangerine-307fe4a3cd4ff2d3910ed992e6e98a7cd3ca6f87.tar go-tangerine-307fe4a3cd4ff2d3910ed992e6e98a7cd3ca6f87.tar.gz go-tangerine-307fe4a3cd4ff2d3910ed992e6e98a7cd3ca6f87.tar.bz2 go-tangerine-307fe4a3cd4ff2d3910ed992e6e98a7cd3ca6f87.tar.lz go-tangerine-307fe4a3cd4ff2d3910ed992e6e98a7cd3ca6f87.tar.xz go-tangerine-307fe4a3cd4ff2d3910ed992e6e98a7cd3ca6f87.tar.zst go-tangerine-307fe4a3cd4ff2d3910ed992e6e98a7cd3ca6f87.zip |
Add loading of extra build in js files to JS-Repl. Implements #67
Diffstat (limited to 'ethereum')
-rw-r--r-- | ethereum/javascript_runtime.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/ethereum/javascript_runtime.go b/ethereum/javascript_runtime.go index 93297f604..b05d39232 100644 --- a/ethereum/javascript_runtime.go +++ b/ethereum/javascript_runtime.go @@ -10,6 +10,7 @@ import ( "github.com/obscuren/otto" "io/ioutil" "os" + "path" "path/filepath" ) @@ -25,6 +26,20 @@ type JSRE struct { objectCb map[string][]otto.Value } +func (jsre *JSRE) LoadExtFile(path string) { + result, err := ioutil.ReadFile(path) + if err == nil { + jsre.vm.Run(result) + } else { + ethutil.Config.Log.Debugln("Could not load file:", path) + } +} + +func (jsre *JSRE) LoadIntFile(file string) { + assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal", "assets", "ext") + jsre.LoadExtFile(path.Join(assetPath, file)) +} + func NewJSRE(ethereum *eth.Ethereum) *JSRE { re := &JSRE{ ethereum, @@ -39,6 +54,10 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE { // Init the JS lib re.vm.Run(jsLib) + // Load extra javascript files + re.LoadIntFile("string.js") + re.LoadIntFile("big.js") + // We have to make sure that, whoever calls this, calls "Stop" go re.mainLoop() |