aichaos / rivescript-go

A RiveScript interpreter for Go. RiveScript is a scripting language for chatterbots.
https://www.rivescript.com/
MIT License
60 stars 16 forks source link

Can't run python macros with rivescript-go interpreter #6

Closed raviteja-ms closed 7 years ago

raviteja-ms commented 7 years ago

I had written a python macro in .rive file. I ran it earlier using python interpreter and it worked fine. But, now when I'm running it using go interpreter it gives me an error. [ERR: Object Not Found]

Please help me..!!

kirsle commented 7 years ago

That's because Go is a different programming language than Python.

The versions of RiveScript written in dynamic languages (Perl, Python and JavaScript) are able to use their own language for object macros, because these three languages have an eval() type function for dynamically loading additional source code of their own language at runtime. So at this time, the only way to use Python object macros in RiveScript is to use the Python version of RiveScript itself, just like the only way to get Perl macros is to use Perl RiveScript.

Go has support for JavaScript via Otto, a Go library that implements a JavaScript interpreter natively in Go. Note that while this is still JavaScript, it isn't necessarily Node-compatible JavaScript (I wouldn't be surprised to see that JS object macros written for the JavaScript version of RiveScript do not work the same in Go). For example, Node is based on the V8 JavaScript engine that Google designed for the Chrome browser, whereas Otto is a custom implementation written from the ground up in Go directly (no relation at all to the V8 engine).

Go can theoretically use Python (or Perl, or Ruby even) by binding with the C interfaces of these languages (e.g. using libpython.h to embed a real Python interpreter inside the Go RiveScript binary which would give it the ability to use Python object macros. But it doesn't do that yet and I don't know enough about C to get the code put together to do that yet, it'd take a lot of research and experimenting first.

raviteja-ms commented 7 years ago

Ok..