-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overloadable Index #263
Comments
I actually agree with this; but only for the fact that |
I'm not entirely following how this is different from the Is this proposing that you should be able to do it in Rune without having to bind the protocols in a Rust module? If so, I think it would be covered by #23 since both |
I think the issue is that this example below doesn't work like it does in Lua which is usually done in Lua for more complex runtime generated "static" type behaviour by basically faking fields or running data whenever the type is used to get a field: rust
rune
I know I have also done this technique before in past, so I can see the desire. |
Ah, right. So module.inst_fn(Protocol::GET, example::get);
module.inst_fn(Protocol::INDEX_GET, example::get); It currently only works as a field function, but either its functionality could be extended to work as an instance fn or add another protocol. |
That sounds perfect to me; I have had to implement systems with a lot of different scripting languages within several projects I have worked on in the past, and out of all of them: Rune does seem like a winner (I love Rust's syntax regardless so I am bias), however I am very used to the aforementioned functionality and admittedly it's hard to go without; it makes the scripts syntax much more digestible for none-programmers I have worked with. |
Can the GET protocol default to INDEX_GET if the property access is not found? |
That is easily the best solution in my honest opinion. |
This is 2 different things which I have used many times in lua for more powerful dynamic object handling, simply the act of overloading what happens when you use either
object.whatever
andobject["whatever"]
, I have used this many times to write dynamic message systems via internal templates to create fully runtime handled objects, this is horrible to use in rust due to fact its a lot of function calls, but in scripting langs it is quite simple and beautiful, for example:in lua I usually override the index function on the userdata and make it simply run the set and get dynamic field functions, allowing me in lua to write this:
I realize this is possible using Object but that comes with 2 issues for me, one it doesn't handle if I try to access or create a field which isn't part of the msg, and it has to be parsed from and into the Object type, as for the dynamic struct system which is great, it requires the scripter to write the structs themselves.
p.s. this example above is purposely simple and far from what the optimized and expanded version would look like.
The text was updated successfully, but these errors were encountered: