9 ms·
> [lua] was discarded because of 3. It has unfamiliar syntax, but worse, unfamiliar semantics: no classes, use tables, start indexing at 1 and other oddities, j
by heinrichhartman 5y ago
> [lua] was discarded because of 3. It has unfamiliar syntax, but worse, unfamiliar semantics: no classes, use tables, start indexing at 1 and other oddities, just as being able to call functions with the wrong number of arguments and returning nil on the way. Also, use tables for both hash tables and arrays. It is powerful, do not misunderstand me, and Lua supports good concurrency. It was just not what I was looking for because of the mentioned things.
I can fully understand why lua is not a good fit for this case, however, I would like to add some color to the picture.
The most powerful way to for C(++) - lua interop, is not the official CAPI but luajit/FFI: https://luajit.org/ext_ffi.html https://luajit.org/ext_ffi.html
This allows for allocation of C objects on the heap and on the stack and FAST function calls. Doing the same for C++ is possible but requires some work e.g. http://lua-users.org/lists/lua-l/2011-07/msg00492.html http://lua-users.org/lists/lua-l/2011-07/msg00492.html
Furthermore:
- unfamiliar syntax -- The syntax is tiny -- and I found nothing unexpected about it.
- no classes -- There are many class libraries available for lua. Just pick one. Used penlight classes quite a bit, without running into major issues.
- use tables for both hash tables and arrays. -- Yes. This is on the API side, under the hood hashes and arrays are used where appropriate.
- pwdisswordfish8 5y agoAlso, > unfamiliar semantics: no classes, use tables, start indexing at 1 and other oddities, just as being able to call functions with the wrong number of arguments and returning nil on the way Other than 1-based indexing, those semantics should be very familiar from JavaScript.
- germandiago 5y agoIt still feels weird to me to call table an array, a hash table and do classes via metatables in very different ways. For sure it is powerful. But it does not fullfill well the zero-friction I was looking for when integrating. You have to change a bit your mindset when integrating and using this stuff. In Wren you have lists, which are basically arrays and dictionaries, ranges and all things I already know how to use from Python/C++. That said, inheritance is not working smooth and ChaiScript does not even have inheritance itself. But for my purposes a class, concurrency and familiar data structures and patters was enough.
- dahfizz 5y agoJavascript is not known for its intuitive and sane design, and certainly not from the perspective of C/C++ devs
- tines 5y agoThe criterion was "familiar", which is nothing if not Javascript -- nobody said anything about intuitive or sane :)
- CraneWorm 5y ago> [...] There are many class libraries available for lua. Just pick one. [...] Alternatively, embrace the prototype-based programming and just... don't add classes.
- pwdisswordfish8 5y agoIn practice though, is prototype-based inheritance useful for anything other than implementing your own class system on top of it?
- CraneWorm 5y agoI hold an opinion that, if you use the prototype-based approach, you should avoid inheritance like the plague ;)
- pwdisswordfish0 5y agoYou should avoid it whether prototypes are involved or not.
- fullstop 5y agoI grumbled about indexing starting at 1, but once you get used to it it makes a lot of problems easier. I've spent the last twenty-ish years in C and string manipulation just sucks. Think about it, you declare a buffer of length 20, the indexes are from 0->19, and the 19th byte needs to be a null if you are using it as a string and are using the entire buffer. Also, the standard library is not guaranteed to null terminate in all situations. Lua's string indexing feels far more natural to me.
- tannhaeuser 5y agoThis. The insistence on using 0-based string offsets is purely a C thing (where it makes sense) inherited on to languages that wanted to stay close to C or appeal to C devs (even though it does not make sense). An easy way to check is looking into awk which, as a DSL for string manipulation written itself in C, deliberately uses 1-based string offsets, and where many/most common string expressions collapse to a very compact form, which makes even more sense because empty string results are interpreted as false in conditions.
- jhvkjhk 5y agoIt's not a C thing, it's a math/utility thing. Dijkstra: Why numbering should start at zero https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- corysama 5y agoWhich is funny because Lua got it’s 1-base from FORTRAN which, I believe, adopted it to make TRANslating math FORmulas easier.
- tovej 5y agoI agree in part that it's a C thing. More accurately it's an offset from the array base thing. The first element is at index 0 because its address is base + 0 * sizeof(element) The second element is at index 1 because its address is base + 1 * sizeof(element)
- _wldu 5y agoLua is the C of scripting languages.