function mod(&x) { x = 5; } local x = 123; mod(x); print(x);
Result desired:
We know existing-Squirrel cannot do this, but is it possible to implement this in Squirrel sqvm.cpp and sqcompiler.cpp?
How to modify integers by reference, like C++ can do
void mod(int& x) { x = 5; } int x = 123; mod(x); printf("%i\n", x);
In Squirrel, the approximate thing is _OP_SETOUTER _OP_GETOUTER. It is used by closure functions
local x = 123; function mod() { x = 5; } mod(); print(x) // x is now 5
|
void SQVM::FindOuter(SQObjectPtr &target, SQObjectPtr *stackindex) |
|
FindOuter(closure->_outervalues[i], &STK(_integer(v._src))); |
|
_parent->MarkLocalAsOuter(pos); |
|
OPCODE_TARGET(SETOUTER) { |
See _OP_SETOUTER _OP_GETOUTER MarkLocalAsOuter() GetOuterVariable() and FindOuter()
function mod()
-----OUTERS
0 x
-----Instructions
[000] _OP_LOADINT 5
[001] _OP_SETOUTER 255 0[x] // could be extended to support true references
[002] _OP_LOADNULLS 1 1
[003] _OP_RETURN 255 0
local x = 123; function mod() { x = 5; } mod(); print(x)
With some modification, could real references be added to Squirrel / Squilu ?:
function mod(&x) { x = 5; } local x = 123; mod(x); print(x);
Result desired:
We know existing-Squirrel cannot do this, but is it possible to implement this in Squirrel
sqvm.cppandsqcompiler.cpp?How to modify integers by reference, like C++ can do
In Squirrel, the approximate thing is
_OP_SETOUTER_OP_GETOUTER. It is used by closure functionssquilu/SquiLu/squirrel/sqvm.cpp
Line 1934 in ef96bae
squilu/SquiLu/squirrel/sqvm.cpp
Line 687 in ef96bae
squilu/SquiLu/squirrel/sqfuncstate.cpp
Line 390 in ef96bae
squilu/SquiLu/squirrel/sqvm.cpp
Line 1162 in ef96bae
See
_OP_SETOUTER_OP_GETOUTERMarkLocalAsOuter()GetOuterVariable()andFindOuter()With some modification, could real
referencesbe added to Squirrel / Squilu ?: