Open shohnwal opened 3 months ago
What you want to do in your example may be possible, but not exactly supported by lua. You would need to use the debug library to replace the value of local variables. See https://www.lua.org/manual/5.1/manual.html#pdf-debug.setlocal
For some alternative approaches see https://github.com/ThePhD/sol2/issues/1323#issuecomment-1060051422
Oh, dumb me, I totally forgot that primitives get passed by value. Never mind then, I'll just use the variadic_results approach then.
Thank you for the links! :)
Some programming languages offer the possibility of out-parameters, aka where the user can pass in arguments as reference to a function, inside the function the value gets modified via reference and once the function returns the value stays modified.
I can modify sol::objects content if they are already of the correct type, as I can just get an already correctly typed reference to their underlying value. however, what if the passed-in sol::object is of a different type, is it possible to replace the referred-to Lua value with a new object?
I know I can always use sol::variadic_results to return multiple values and do
but I was wondering whether it's possible to mimic out-parameters somehow, as it would be more consistent with what some people are used to with other languages.
By the way, thank you for this fantastic work. I have been using sol2 for years and I am very happy with it!