Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Lua 5.2/Split() function

edited March 2013 in Suggestions Posts: 2,820

I haven't wanted Lua 5.2 in Codea, until I learned about the split/join functions. Of the Lua version of Codea could be updated ASAP, that would save me a lot of work. Thanks!
Look here to learn about Split/Join:


  • Posts: 146

    what do you mean? Those functions are for 5.1 as well...

  • Posts: 2,820

    @gunnar_z - They don't seem to be working in Codea.

  • Posts: 146

    note that some of those have been created for 5.0, which is not 100% compatible with 5.1 (just like 5.1 is not 100% compatible with 5.2, which is why just plugging in the new interpreter into codea is going to cause some grief..,). Which example were yiu trying, and how does it not work?

  • Posts: 2,820

    @gunnar_z - the functions Split() and Join() are of Lua 5.2, so none will work. I made a workaround, so don't worry about it. I might try and write my own version of these functions.

  • Posts: 146

    There are no functions split() and join() in 5.2 . There is table.concat(), which is somewhat equivalent to join(), and string.gsub(), which can be used to make sth like split().

  • edited March 2013 Posts: 68

    -- Compatibility: Lua-5.1
    function split(str, pat)
       local t = {}  -- NOTE: use {n = 0} in Lua-5.0
       local fpat = "(.-)" .. pat
       local last_end = 1
       local s, e, cap = str:find(fpat, 1)
       while s do
          if s ~= 1 or cap ~= "" then
          last_end = e+1
          s, e, cap = str:find(fpat, last_end)
       if last_end <= #str then
          cap = str:sub(last_end)
          table.insert(t, cap)
       return t


  • Posts: 2,820

    @Diablo76 - Cool. Thanks!

Sign In or Register to comment.