[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Chaning code at run time
- From: "Robert G. Jakabosky" <bobby@...>
- Date: Thu, 7 Aug 2008 17:33:26 -0700
On Thursday 07, Jonathan wrote:
> I would like to be able to change the following lua function at run time:
>
> function new_foo()
> local foo_update = function()
> -- do something
> end
>
> return { foo_update = foo_update }
> end
>
> foo.foo_update() -- foo was created during initialization
>
> Is there any way to change foo_update during run time? If not, then is
> there another way to create objects which allows me to change them at run
> time?
You could use "dofile" to re-load the code that you want to update.
foo.lua:
function foo_update()
print("foo version 1")
end
return { foo_update = foo_update }
main.lua:
-- initialize foo object.
foo = dofile("foo.lua")
foo.foo_update() -- call first version.
-- make changes to foo.lua
foo = dofile("foo.lua") -- load new version
foo.foo_update() -- call new version.
--
Robert G. Jakabosky