lua-users home
lua-l archive

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


Hi,
Maybe a beginners question.
No notion whether I am blind or impudently,
I'am missing one kind of "function definition comfort".

>From my "scripting background" (using MatLab- or ANSYS-Scripts),
I "define" a function by writing a script file (let's say "foo.lua")
and then "call" it by using the filename.

Example (pseudeo code):

File "foo.lua": [[
  local tmp = ARG[1]                       -- argument passing
  msg = "foo.lua was called with ARG"..tmp -- side effects
  return 1                                 -- return value(s)
]]

and

File "testfoo.lua": [[
  msg = "foo.lua not called till now"
  val = foo("Hi")
  print("MSG:"..msg)
  print("val:"..val)
]]

My questions are:
Is there a (better) way to do such a "auto-dofile with args"?
Are there conceptional or philosophical reasons against such a thing?

Thanks for your work.
Frank

P.S.
Of course the following will work also

File "foo2.lua": [[
  function foo2(...)
    local tmp = ARG[1]
    msg = "foo2.lua was called with ARG"..tmp
    return 1
  end
]]

and

File "testfoo2.lua": [[
  dofile("foo2.lua")
  msg = "foo2.lua not called till now"
  val = foo2("Hi")
  print("MSG:"..msg)
  print("val:"..val)
]]

But, I am lazy and prefer the first (automagic) version.