how can i call a function by a string?

Seraphim8400

Warlord
Joined
Nov 7, 2010
Messages
112
i try like this
Code:
stemp = stemp .. "_HM" .. "1";
        print(stemp);
        _G[stemp]();
but log
Code:
HistoricalEnd: sino_HM1
Runtime Error: [string "Historical end/HistoricalEnd.lua"]:140: attempt to index global '_G' (a nil value)

i try another way
Code:
loadstring(stemp .. "()")();
then it error too
Runtime Error: [string "Historical end/HistoricalEnd.lua"]:140: attempt to call global 'loadstring' (a nil value)

so how can i call function sino_HM1() by a string value "sino_HM1"?
 
do you mean something like this
Code:
local tbl = { ab = function(a) print(a); end, }; 

local a = "a"; 
local b = "b"; 

local string = a .. b; 

tbl[string]("hello");
 
Back
Top Bottom