lua-users home
lua-l archive

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


You could remember the globals before the config script is called, then
get the globals afterwards and process the difference, deleting the
functions if necessary. There is some set code on the wiki I wrote Lua4
you could use.


> function CfgMain()
> {
>     Damage =
>     {
>         { 5, 10, 15, 20 },
>         { 7, 12, 17, 23 },
>         { 8, 14, 19, 29 }
>     }
> 
>     for key, value in Damage do
>         CfgDamage( Damage[1], Damage[2] , Damage[3] )
>     end
> 
>     Damage = nil
> }
> CfgMain()
> CfgMain = nil

Or, avoid fn names:

config = {}
function add_config(fn)
  tinsert(config,fn)
end

-----

-- scripters add:

add_config(
   function()   -- note anonymous
     local Damage =
     {
         { 5, 10, 15, 20 },
         { 7, 12, 17, 23 },
         { 8, 14, 19, 29 }
     }
 
     for key, value in Damage do
         CfgDamage( Damage[1], Damage[2] , Damage[3] )
     end
 
     -- Damage = nil -- Damage is local
  end)


-- call config
foreach(config, function(f) f() end)
config = nil



>   This will work but its prone to error since you are leaving it up to
the
> scripters to play nice and they never do :)
> 
>   Thanks for the pointers, maybe I should look into Virgil Smith's
method
> if
> its not too much work.  Man I wish I had started with Lua 5 :(

Have you heavily customised Lua? I think your scripts should be portable
and if you haven't altered Lua it should be an hour long job to swap
over (if that!). Delete Lua4, insert Lua5, make doubles floats, change
longs to ints, change Lua_open params, change call to pcall and add
error handler, mmm anything else?

Nick