Posted 12 February 2016 - 02:41 PM
Is there a way I can check if a string is the same name as an existing function?
I'm using this line of code to execute a string stored in the object[id].type
But sometimes there are no function with the same name as the string in the object[id].type and the code wont works because its calling a function that doesn't exist
So I'm trying to check like this if the string is a function but it appears to only return it as string type and not the one I wanted to happen
So is there any way I can check if a string is also a function with the same name? or any other fix I can apply in here?
P.S.
I'm using this code as a module and whenever I use _G[]() it says I'm calling a nil so I'm forced on using loadstring() and assert()
I'm using this line of code to execute a string stored in the object[id].type
assert( loadstring( 'return ' .. object[ id ].type .. '.print' .. '( ... )' ) )()
But sometimes there are no function with the same name as the string in the object[id].type and the code wont works because its calling a function that doesn't exist
So I'm trying to check like this if the string is a function but it appears to only return it as string type and not the one I wanted to happen
if type(object[id].config.type.. '.print') == 'function' then
assert( loadstring( 'return ' .. object[ id ].type .. '.print' .. '( ... )' ) )()
end
So is there any way I can check if a string is also a function with the same name? or any other fix I can apply in here?
P.S.
I'm using this code as a module and whenever I use _G[]() it says I'm calling a nil so I'm forced on using loadstring() and assert()
module( ..., package.seeall )
Edited on 12 February 2016 - 01:42 PM