I'm looking forward to using a variable like "asdf" instead of writing the name function to check its return (which changes now and then). That's why "asdf" variable should update its value everytime we use (call) it
Is there any way to do this in Lua, please?
asdf == getFunction() --we define it here
(...) --some code
if asdf < 10 then ... --here we call the variable (so it should get/update again the result of getFunction())
thanks
--we define it here
local asdf = function ()
return getFunction()
end
--some code
(...)
--here we call the variable
--(so it should get/update again the result of getFunction())
if asdf() < 10 then ...
UPD :
Solution without parenthesis
--we define it here
asdf = nil
setmetatable(_G, {__index =
function(t, k)
if k == 'asdf' then
return getFunction()
end
end
})
--some code
(...)
--here we call the variable
--(so it should get/update again the result of getFunction())
if asdf < 10 then ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With