0

Are there any stl implementations for lua? I understand we can use table instead of the stl facilities when programming in lua,but it is really not friendly to be used,so I am wondering the stl implementations in lua,especially the vector,map,list,set.

Koo
  • 11
  • 2
  • 4
    No, and rightfully so. The concepts from the STL translate very badly over to a dynamically typed language like Lua. Embrace the flexibility offered by tables and try to understand how to use their specific strengths to work efficiently and you will probably not miss it much. – ComicSansMS Jul 15 '14 at 15:30
  • 1
    What operations on which structures are you having trouble with? – Tom Blodget Jul 15 '14 at 16:19
  • 1
    Vector/list: use tables with numeric keys. Map: tables with any keys. Set: tables with the set contents as keys and a placeholder value (like `true`) as values. – Colonel Thirty Two Jul 15 '14 at 17:10
  • @ColonelThirtyTwo you should make that into an answer, I was going to then saw your comment – Oliver Jul 16 '14 at 01:29
  • @Schollii The STL is more than just containers. – ComicSansMS Jul 16 '14 at 06:57
  • @ComicSansMS there is no indication by OP that they need anything but the container capabilities (insert, sort etc). – Oliver Jul 16 '14 at 17:51
  • @ComicSansMS,I just want the container and his implication,like data is sorted in map by its key – Koo Jul 17 '14 at 04:34
  • You may want to check [Penlight](http://stevedonovan.github.io/Penlight/api/index.html) and [lua-stdlib](https://github.com/lua-stdlib/lua-stdlib/). – lhf Jul 17 '14 at 10:47
  • You are right, in Lua, a table has no manifest order. But just as in the STL, you can supply an algorithm to an iterator. If you want a sorting iterator, see this [answer](http://stackoverflow.com/a/15706820/2226988). – Tom Blodget Jul 17 '14 at 16:51
  • @ComicSansMS Using non-table data structures in lua is still possible though, and occasionally a good idea. – Cubic Aug 11 '14 at 11:34

1 Answers1

2

A library exists to use C++ containers in Lua. See :

But you can also use containers written in pure Lua :

People in comments recommend you to use the Lua table structure as you need. If you need only simple data types and algorithms (for instance set with insertion, removal and test), you should. But if you need more complex algorithms, these libraries are a good choice.

Alban Linard
  • 1,037
  • 9
  • 19