google / jsonnet

Jsonnet - The data templating language
http://jsonnet.org
Apache License 2.0
6.92k stars 436 forks source link

native extensions should support returning all jsonnet types. #202

Open mikedanese opened 8 years ago

mikedanese commented 8 years ago

numbers, objects, arrays, functions?

sparkprime commented 8 years ago

I added numbers, booleans, null with #199.

I don't think we want to pass Jsonnet objects, functions, or arrays over, but JSON objects and arrays ought to work. The difference between Jsonnet objects / arrays and JSON objects / arrays is that the Jsonnet ones can contain Jsonnet values (as opposed to just JSON values) and also we need to recursively force all the thunks / expand the fields to convert to JSON. Converting them back again is also not trivial because HeapSimpleObject's fields are ASTs, so we'd have to create an AST to represent a value, but the AST references are not garbage collected, they are pooled in the Allocator and cleaned up when you destroy the VM (there are only supposed to be finitely many of them, created during parsing). So we'd probably need to add a HeapForcedObject or something like that.

If we give Jsonnet objects to the caller, then we have to worry about interfacing with garbage collection (reference counting?) and also there is not much they can do with them other than pass them back again. We'd have to provide even more functions to allow them to call the functions, or whatever other interactions make sense.

sparkprime commented 8 years ago

You can now return anything, but native functions can still take only primitves.

sparkprime commented 8 years ago
def parse_yaml(str):
    return yaml.load(str)

native_callbacks = {
    'parse_yaml': (('str',), parse_yaml ),
}
mikedanese commented 8 years ago

I agree that json types are sufficient. Accepting objects and arrays would still be nice.