PistonDevelopers / dyon

A rusty dynamically typed scripting language
Apache License 2.0
1.77k stars 55 forks source link

Add variable to module #649

Open shelllet opened 5 years ago

shelllet commented 5 years ago

how to add variable? i use v8 before and then i want to change to rust from c++. i look for all doc and find way to add function by module.add or module.add_str, but i can't find how to add variable. dyon support this?

bvssvni commented 5 years ago

Dyon does not have global variables, but instead uses current objects:

fn main() {
    ~ a := 2
    foo()
}

fn foo() ~ a: f64 {
    // `a` is available in this scope
}
shelllet commented 5 years ago

thanks for your reply, i felt frustrated because i wan't to manipulate rust variable from Dyon.
like v8

  v8::Local<v8::ObjectTemplate> hkey = v8::ObjectTemplate::New(isolate);
    hkey->SetLazyDataProperty(V8_NEW_STRING(isolate, HKEY_CLASSES_ROOT), [](v8::Local<v8::Name> /*property*/,
        const v8::PropertyCallbackInfo<v8::Value> & info) {
            info.GetReturnValue().Set(v8::External::New(info.GetIsolate(), HKEY_CLASSES_ROOT));
        });