Custom getters and setters in C/C++
See original GitHub issueIs 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:
- Created 5 years ago
- Comments:8 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.
@sazlang Any updates or ready to close?