lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, 9 Jan 2002, Markus Huber wrote:

>    why doesn't work the following example?
>
>    Name='Test'
>    function Test_Version() return 001 end
>    print(dostring(Name..'_Version()'))
>
>     Prints: userdata(0): 00000000
> But I need: 1

As a rule, you should always avoid using dostring if you can (it is too
expensive). A better way to do what you want is with getglobal:

  print(getglobal(Name..'_Version')())

Or, if you want to check for errors,

  local f = getglobal(Name..'_Version')
  if type(f) == 'function' then print(f())
  else ...
  end

-- Roberto