Page 1 of 1

Howto: expand variables

Posted: Sat Aug 22, 2009 4:29 am
by eraldo
Example:

Global variable:
MyNumber = 10

function:

Code: Select all

        testFunction(a, b)
            local VariableNameString = a .. b
            local value = tonumber( VariableNameString )
            echo( value )
        end


Function call:
testFunction( "My", "Number" )

Result:
10

Re: Howto: expand variables

Posted: Thu Nov 26, 2009 8:03 pm
by Xinael
Or:

echo(_G["My" .. "Number"])

_G is the global table.