relationsone / gomini

Go + Typescript for Embedded development? Not Possible? It is, Gomini!
Apache License 2.0
4 stars 1 forks source link

Add support for object mapping to automatic JavaScript objects #8

Open noctarius opened 6 years ago

noctarius commented 6 years ago

Even though goja supports a simple form of automatic object mapping, other implementations of JS VMs might not. Further more goja is missing some more advanced features which are provided by the ObjectCreator functions, anyhow using the ObjectCreator system for lots of objects is too complex and error prone. Automatic object mapping is supposed to be a more convenient and easy API to use.

Something like the following method is proposed:

ObjectCreator::DefineGoObjectProperty(name string, object interface{}) ObjectBuilder

The object itself defines its mapping like:

type path struct {
    Name    string                                 `gomini: "constant=true, name=name"`
    Path    string                                 `gomini: "constant=true, name=path"`
    Type    filetype                               `gomini: "constant=true, name=type"`
    Exists  func(gomini.FunctionCall) gomini.Value `gomini: "name=exists"`
    Mkdir   func(gomini.FunctionCall) gomini.Value `gomini: "name=mkdir"`
    Resolve func(gomini.FunctionCall) gomini.Value `gomini: "name=resolve"`
    ToFile  func(gomini.FunctionCall) gomini.Value `gomini: "name=toFile"`
    ToPipe  func(gomini.FunctionCall) gomini.Value `gomini: "name=toPipe"`
}