-
Notifications
You must be signed in to change notification settings - Fork 156
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
Function Reference Parameters (Extending the 'outer' system) #293
Comments
No need to, see WEAKREF. |
Weakref cannot work because We will modify Squirrel to make the VM instructions support arbitrary references. function mod(&x) { x = 5; } local x = 0; mod(x); print(x); will output:
We know existing-Squirrel cannot do this, but Squirrel is open source so we're looking for comments on how to implement integer references natively in Squirrel's C++ code. Our users want to directly modify integers by reference, without using a wrapper.Again, the closest thing is Using Squirrel's Outer system, we can extend Squirrel to support general references. It requires editing Take Squirrel's local x = 0; function mod() { x = 5; } mod(); print(x) // x is now 5 With some modification function mod(&x) { x = 5; } local x = 0; mod(x); print(x);
We will redesign Squirrel's C++ code to accommodate this feature.
local x = 0; function mod() { x = 5; } mod(); print(x) // x is now 5 |
I can see this working for local variables but it wouldn't work for variables that are not in the stack. Also I can't imagine what we would pass as parameter so that the called function would recognize that is a reference. It is more complicated that it sounds. |
So Squirrel language already has 'outers' which act like references:
Squirrel "Outers" are almost references, but Squirrel's outers are limited to local variables in the
_parent
function.So, with some modification of Squirrel's outer system, how can we implement this feature:
For Syntax: Parsing
&
inCreateFunction
would need to call something likeMarkLocalAsOuter()
for each&
reference parameterThen for runtime
Possibly take this code from
SQVM::CLOSURE_OP()
...And setup "references" in
_OP_PREPCALL
so the reference stack is setup before the function gets called,Any idea for how to extend the
outer
system and implement references?It would be really cool for Squirrel.
The text was updated successfully, but these errors were encountered: