question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom getters and setters in C/C++

See original GitHub issue

Is there any way to bind getter and setter for JS variable from C? Something like that.

int myVariable = 0;

int myVariableGetter() { return myVariable; }
void myVariableSetter(int v) { myVariable = v; }

int main() {
  ...
  duk_bind_getter_for("myVariable", myVariableGetter);
  duk_bind_setter_for("myVariable", myVariableSetter);
  duk_eval_string(ctx, "myVariable = 5;");
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
svaaralacommented, Aug 16, 2018

There are some Ecmascript-based Proxy examples here: https://wiki.duktape.org/HowtoVirtualProperties.html. The C API call for creating a Proxy is https://duktape.org/api.html#duk_push_proxy if you’d rather initialize the Proxy from C code.

0reactions
svaaralacommented, Sep 17, 2018

@sazlang Any updates or ready to close?

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# Custom getter/setter without private variable - Stack Overflow
I know the compiler makes a private instance variable down in it's murky depths when one uses autos, but I'm spoiled and don't...
Read more >
Learn C# Properties: Getters and Setters at ... - CodeEasy
"To create a property, use the same syntax as for fields, but add a get; to generate a getter and a set; to...
Read more >
Is it good idea to set custom-defined getter and setter in c# ...
1 Answer 1 · Make the property read-only by removing the setter. · Add the flag inside your class which will tell if...
Read more >
Getters setters and auto properties in C# explained { get; set
With that in mind, don't add setters and getters by default. If a variable does not need to be accessed at all by...
Read more >
set; } when not actually using custom getters/setters? : r/csharp
Also with a property 'get' can be public, and 'set' can be private. So other classes can read the value, but you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found