3 ms·
People keep laughing at PHP for being a joke language but has anyone ever looked at the Lua internals? Probably not, because you wouldn't make it out of that he
by pearjuice 12y ago
People keep laughing at PHP for being a joke language but has anyone ever looked at the Lua internals? Probably not, because you wouldn't make it out of that hell alive. I am amazed they still manage to add variable types and bitwise operators without completely overhauling the language.
- Avshalom 12y agoI haven't but Lua is frequently held up as an example of an excellent code base.
- groovy2shoes 12y agoWhat's so hellish about the Lua codebase? I've found it extremely understandable and hackable. The parser is a recursive descent, syntax-directed translator to bytecode. Adding new operators amounts to adding extra token checks to the expression parsing section of the code and generating the appropriate bytecode. The VM itself is even simpler, and adding a new 'type' is just a matter of adding the extra case to the Value union, a new discriminator for the tag, and a handful of extra functions for dealing with it. Sure it's a little complicated, but language implementation is a complicated topic. It's hard for me to imagine Lua's code being much simpler than it is. Not sure what Lua's internals have to do with PHP, though.
- haberman 12y agoQuite the opposite, Lua is one of the leanest and most efficient dynamic language implementations out there. Its design is actually really clean, if you take the time to learn it. Here is a tour guide of the code base, written by Mike Pall (author of LuaJIT, not Lua, but obviously quite familiar with the Lua code base): http://www.reddit.com/r/programming/comments/63hth/ask_reddit_which_oss_codebases_out_there_are_so/c02pxbp http://www.reddit.com/r/programming/comments/63hth/ask_reddi...
- catwell 12y agoPUC Lua is about 20k lines of ANSI C code. The "ANSI" part makes it a bit old-fashioned sometimes but it is very readable. Maybe you were thinking about the LuaJIT code base? That one is indeed very tricky, in part because a lot of it is in ASM and in part because the algorithms behind it are very tricky. I doubt anybody other than Mike Pall understands it all.