{"id":581,"date":"2011-09-23T19:00:00","date_gmt":"2011-09-23T18:00:00","guid":{"rendered":"http:\/\/shadowcovenant.com\/blog\/2011\/09\/23\/lua-syntax\/"},"modified":"2011-09-23T19:00:00","modified_gmt":"2011-09-23T18:00:00","slug":"lua-syntax","status":"publish","type":"post","link":"http:\/\/shadowcovenant.com\/blog\/2011\/09\/23\/lua-syntax\/","title":{"rendered":"LUA syntax"},"content":{"rendered":"<p align=\"justify\">I love <a href=\"http:\/\/www.lua.org\/\">Lua<\/a> for scripting\u2026 It\u2019s easy to integrate with any C\/C++ framework, powerful, fast, takes little memory, good debugging hooks, memory control, and (best of it all) it has coroutines, which is something that I utterly love in game development.<\/p>\n<p align=\"justify\"><a href=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2011\/09\/lua.gif\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"lua\" border=\"0\" alt=\"lua\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2011\/09\/lua_thumb.gif\" width=\"244\" height=\"243\" \/><\/a><\/p>\n<p align=\"justify\">But this is not an article praising Lua\u2026 To the contrary, it\u2019s a rant about the stuff that annoys me in it and that I wish someone would fix\u2026 I know most of this could be fixed by me, since Lua is Open Source, but to be honest most of it would be a huge endeavor in the guts of Lua itself.<\/p>\n<ol>\n<li>\n<div align=\"justify\"><strong>Why 1-based arrays?<\/strong> Every language I know of has 0-based arrays (that is, arrays that start at position 0), but Lua had to be different\u2026 This is not a big problem per se, but the amount of times you do it wrong because you\u2019re shifting from C\/C++ to Lua is huge\u2026 Probably someone that sticks to Lua can do it without messing up a single time, but I\u2019m an indy programmer!<\/div>\n<\/li>\n<li>\n<div align=\"justify\"><strong>Why THEN and END? <\/strong>This is my main annoyance with Lua\u2026 All IFs in Lua have to have the keyword THEN after the condition, and END up when the syntax block ends\u2026 I understand being mandatory an instruction block (i.e. not allowing for a single instruction), since that leads to some ambiguities and tricky to spot bugs sometimes, but couldn\u2019t they have used \u2018{\u2018 and \u2018}\u2019, or even \u2018[\u2018 and \u2018]\u2019, or something else but a clunky keyword that makes your code seem ugly? On the same note, the FOR and WHILE loops also require the DO keyword, which also sucks\u2026 is it that complicated to make a parser that doesn\u2019t need those things?<\/div>\n<\/li>\n<li>\n<div align=\"justify\"><strong>Use of doubles for numbers<\/strong>. This one I understand\u2026 numbers in Lua are expressed as doubles (which allows them to be fractional and yet provide a good range of integer numbers without loss of precision). But when you\u2019re making games, you don\u2019t want to keep switching between single and double precision on the FPU, and Lua kind of forces it (since you\u2019re probably using floats all the time for everything else, like meshes). Adding an integer type and going for floating point numbers would help tremendously here (although I believe it wouldn\u2019t be such a simple task as I\u2019m stating, since the typeless nature of Lua makes it complicated, but I wouldn\u2019t mind having some methods to work with floating point numbers, and others for integers for this purpose). The way I have it now, I do a compilation of Lua with numbers as floats for my game projects, and cross my fingers so that the precision doesn\u2019t byte me in the future.         <br \/>What I do is when I want to treat a number as an integer (in comparisons and things like that), I round to the nearest integer\u2026 Hopefully that\u2019s enough to stop some problems (which might be tricky to debug, since 3.9999999 != 4)<\/div>\n<\/li>\n<li>\n<div align=\"justify\"><strong>Lack of types<\/strong>. This one isn\u2019t really Lua\u2019s fault (since most languages don\u2019t do this), I would just really really really appreciate if I could have 2, 3 and 4 dimension vectors treated as internal types, so that I could use vector math in Lua (without the performance hit I get when I use arrays as vectors)<\/div>\n<\/li>\n<li>\n<div align=\"justify\"><strong>Lack of pre-processor. <\/strong>Again, not Lua\u2019s fault, but it would be nice to have a preprocessor in Lua\u2019s parser\u2026 I can run stuff through the C preprocessor and feed that result to Lua, but that screws up debugging a bit, which is too bad\u2026<\/div>\n<\/li>\n<li>\n<div align=\"justify\"><strong>Lack of a class based system.<\/strong> I know I can use meta-methods and tables to mimic a class in Lua, but that\u2019s not the same. Imagine that I return an object from C code. That implies that I \u201ccopy\u201d the data from the C++ object to a Lua table, and push also some functions (C\/C++ and Lua). This sounds terribly inefficient. It would be better to be able to specify some classes (with the methods associated to them), and just copy the data on top of the table. You might be able to do this with some trickery, but I haven\u2019t found the trick yet, I admit. This one isn\u2019t very serious, since Lua never pretended to be an OO language, and I can live just fine with passing some light user data values back and forth between Lua and C\/C++.<\/div>\n<\/li>\n<\/ol>\n<p align=\"justify\">&#160;<\/p>\n<p align=\"justify\">I\u2019ve looked into several other scripting languages (mainly Javascript (through the V8 engine) and Python), and they have more serious handicaps for my taste than Lua, and that\u2019s why I keep using Lua.<\/p>\n<p align=\"justify\">Some of these seem pretty easy to fix for the developers (or someone that really takes the time to delve into the Lua source-code). Of course, changing these, will it still be Lua? I like to think that it would some sort of Lua+, different yet better. Maybe one of these days I\u2019ll take the time to fix 1, 2 and 4 (well, 1 and 2, 4 might be too hard). If anybody knows someone that\u2019s actually done some of this, feel free to give me a poke! <img decoding=\"async\" style=\"border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2011\/09\/wlEmoticon-smile4.png\" \/><\/p>\n<div id=\"tweetbutton581\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F09%2F23%2Flua-syntax%2F&amp;text=LUA%20syntax&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F09%2F23%2Flua-syntax%2F\" class=\"twitter-share-button\"  style=\"width:55px;height:22px;background:transparent url('http:\/\/shadowcovenant.com\/blog\/wp-content\/plugins\/wp-tweet-button\/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;\">Tweet<\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>I love Lua for scripting\u2026 It\u2019s easy to integrate with any C\/C++ framework, powerful, fast, takes little memory, good debugging hooks, memory control, and (best of it all) it has coroutines, which is something that I utterly love in game development. But this is not an article praising Lua\u2026 To the contrary, it\u2019s a rant [&hellip;]<\/p>\n<div id=\"tweetbutton581\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F09%2F23%2Flua-syntax%2F&amp;text=LUA%20syntax&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F09%2F23%2Flua-syntax%2F\" class=\"twitter-share-button\"  style=\"width:55px;height:22px;background:transparent url('http:\/\/shadowcovenant.com\/blog\/wp-content\/plugins\/wp-tweet-button\/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;\">Tweet<\/a><\/div>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,6],"tags":[],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-development","category-games"],"_links":{"self":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/comments?post=581"}],"version-history":[{"count":0,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/581\/revisions"}],"wp:attachment":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/media?parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/categories?post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/tags?post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}