lua-users home
lua-l archive

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



yes, we use C++ preprocessor for this purpose, but it is very hard to
debug such code, it would be much easier to have this function
implemented in Lua.
I added #ifdef functionality it to my project using token filters

   See http://lua-users.org/lists/lua-l/2007-05/msg00176.html

It is easy to do and works well.
But, actually, the main feature we need - it's Edit & Continue, it
would be orders of magnitude easier to debug programs with it.
Getting Edit & Continue to work in a Lua project is not that difficult.

All you have to do to reload a file is to run "dofile" instead of "require" on the file. If you want to reload all your files, just clear the require cache

   package.loaded = {}

and run your startup file again. You also need to take some care when writing your lua files so that they are "reentrant" and behave nicely when reloaded, i.e., instead of writing your class definitions like this:

   Car = {}
   function Car:run()
      ...
   end

Write:

   Car = Car or {}
   function Car:run()
      ...
   end

Now if you reload the file, the old Car-class will be retained (so objects keep the right metaclass), but the function definitions in the Car class will be updated.

// Niklas