lua-users home
lua-l archive

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


>   if dostring('return '..Name..'_Version()')<Version then
>      print('Version to old')
>   end
>
>If there is an error executing this dostring, e.g. if Name = 'Other'
>then dostring shows an error message:
>"error: attempt to call global 'Other_Version' (a nil value)"
>and then
>"error: attempt to compare nil with number"
>How can both suppressed?

How about this (untested)?

	function getversion(Name)
	 local error=_ERRORMESSAGE
	 _ERRORMESSAGE=nil
	 local version=dostring('return '..Name..'_Version()') or 0
	 _ERRORMESSAGE=error
	 return version
	end

Setting _ERRORMESSAGE temporarily to nil prevents error messages.
Also, note "or 0"after dostring, that is, getversion returns 0 in case of
errors.
--lhf