Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would make it easier to really work with Lua?

Tags:

lua

I love Lua, using it for more and more projects as the primary (not embedded) language. My current project is approaching 10,000 lines and will probably end at about 15,000 lines. What have you found useful when developing in Lua at that scale? What have you bumped your head against, and what solutions have you found? I'm thinking about development tools, language features & techniques, third-party modules?

My top 3:

  1. strict.lua - I use a modified version of this. Without being alerted to accesses of unused/unintended variables I'd go crazy.

  2. coroutines - not for their multithreading capability, but for their continuability. Very useful for simplifying the implementation of state machines.

  3. serialization function - indispensable for dumping table contents, and for persisting tables to disk (I use this many times when otherwise I'd probably have reached for a database).

My Wishlist:

  1. Visual debugger for OS X. I'm using print()s now, but a debugger that would let me single-step through source files would be great.

  2. A continue statement. Using the repeat...until true workaround is ugly, and too many nested ifs becomes complex and ugly.

  3. A metamethod that's invoked when an existing table member is modified.

Any other tips for larger-scale Lua development?

like image 626
proFromDover Avatar asked Feb 03 '23 01:02

proFromDover


2 Answers

A continue statement. Using the repeat...until true workaround is ugly, and too many nested ifs becomes complex and ugly.

Have your loop body be a function call; then return becomes continue.

A metamethod that's invoked when an existing table member is modified.

You can implement this yourself by using a proxy table B that stores all of the actual data for table A - the newindex/index metamethods on A intercept writes/reads and modify/lookup from table B instead. Since A never gets anything written to it, all writes hit newindex.

like image 190
Amber Avatar answered Feb 05 '23 15:02

Amber


Based on your top3 and wish lists, here are the products I worked on and can recommend (at least based on the feedback I received):

  1. MobDebug: a remote debugger based on RemDebug, but with a variety of fixes and new functions.
  2. ZeroBrane Studio: a Lua IDE that provides a debugger with all expected functions (StepIn/Over/Out, Break, Watch, Stack, Breakpoints, remote shell, serialization support, coroutine support and more) and runs on OSX and Windows. It provides a seamless integration with MobDebug in the IDE. I posted several screencasts showing it in action: http://notebook.kulchenko.com/zerobrane/live-coding-in-lua-bret-victor-style, http://notebook.kulchenko.com/zerobrane/love2d-debugging.
  3. Serpent: a compact and powerful serializer. ZeroBrane Studio is using Serpent to display complex data structures in the Console and Stack windows.
  4. ZeroBrane Studio includes a static analyzer (based on metalua and lua-inspect), which allows you to detect same issues (and more) that strict.lua detects, but during development (before you run the code).
  5. In terms of watching changes, MobDebug provides a way to do that for any type of variables (not just table). I've described it in another SO post. This functionality is not available through ZeroBrane Studio yet.
like image 41
Paul Kulchenko Avatar answered Feb 05 '23 16:02

Paul Kulchenko