Ideas for Some Additional Language Features / Framework


#1

Hi,

I am relatively new to chai. I am interested in using it in an existing open source project I am working on. This is a distributed terra-scale graph database. I need some sort of scripting/query language for it, and am considering chai for this role.

I would like to look into adding a few new language features:

(1) The possibility for spinning up chai server instances, and a standardized chai client:

Implement a multithreaded server supporting TLS, LDAP, Vault, sandboxes, with users, security groups, sessions, etc.

(2) Language extensions that will support chai-based RPC between chai clients and chai server instances:

Implement a language syntax something like:

remote foo = remote("foo.com"); // Connect to a remote chai instance at foo.com.
if (!foo.connected) throw "Could not connect to " + foo.address;

def my_fn(x, y) { // Declare any function or class locally.
    return x + y;
}

my_fn >>> foo; // Now transmit it to foo (assuming I have permission).
var ret = foo.my_fn(5, 7); // Call my_fn via RPC so that it will be executed on 'foo'.
var foo_fn <<< foo.my_fn; // Get the code back from foo.
ret = foo_fn(9, 11); // Called locally.

// Try it with a class.
class complex { attr re; attr im; def complex(r,i) { this.re = r; this.im = i; } } // A class declaration.
var mycplx = complex(1.0, 0.777); // Create a local instance.
mycplx >>> foo; // Transmit the class and instance data, in total, to foo.
assert(foo.mycplx.im == 0.777); // Now call a remote method on it.

In addition, one could create and populate remote namespaces, transmit class definitions, class instances (with the object state), etc., mostly by using a ‘>>>’ or ‘<<<’ operator syntax and the ‘remote’ keyword. The underlying serialization, security and protocol would all be handled behind the scenes.

So, this would require being able to walk the AST and state on a given object to recover the actual chai code and data that would be transmitted.

The server, perhaps ‘chaisvc’, would be fairly boilerplate.

Any ideas / suggestions?

Regards,
Kristen


#2

Hm. That is kind of interesting. But as a addition to core ChaiScript… i think that’s out of scope. Also i think you could do something like that using ChaiScript as it is. Maybe with a slighty different syntax, but in the end you could just use ChaiScript to call stuff that sends script around and provides RPC frontend/backend in c++. But while rather flexible i also think that for specific applications, a specific set of RPC protocol will probably be more efficient than a scriptable. There would be a lot of caveats to consider - think of all the ways someone might send evil script to the server. A simpler but unambiguous protocol would probably be easier to implement for most purposes. Nevertheless interesting - i could imagine using something like that to transmit between a game server and client.


#3

ChaiScript_Extras_Http provides an interface to Http.h.