lua-users home
lua-l archive

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


On Sunday 21 March 2004 00:33, Nightowl wrote:
> LUA: ..\examples\lua_00.lua:32: attempt to call global `getargs' (a nil
> value)

The script you are trying to run was written for Lua 4. The getargs function 
no longer exists in Lua 5. The equivalent Lua 5 program (also tidied up to 
remove superfluous statements, brackets, and semicolons) is this:

print("\nLua_00 - lists the given command line arguments\n")

local ArgCount = table.getn(arg)

if ArgCount == 0 then
   print("(no arguments given)")
else
   if ArgCount == 1 then
      print("got one argument:")
   else
      print("got " .. ArgCount .. " arguments:")
   end

   for i = 1, ArgCount do
      local Argument = tostring(arg[i])
      if string.len(Argument) > 70 then
	 Argument = string.sub(Argument,1,67) .. "..."
      end
      print(string.format(" %2d) \"%s\"", i, Argument));
   end
end

I'd suggest you find yourself a different source for example code: aside from 
being out of date, the style of the code on that site is really quite bizarre 
in places.

-- Jamie Webb