implode PHP in LUA

2

I have the following code that passes a php array to JS:

var js_array_date1 = [<?php echo '"'.implode('","', $newarray_date1).'"' ?>];

My problem is how can I do this in LUA. Passing an LUA array to JS, I know I have to use table.concat()

    
asked by anonymous 14.05.2015 / 11:51

1 answer

5

From what I understand (correct me if I'm wrong), you need a function that gives a vector V and a separator S, returns a string with each of the elements in V concatenated in order and separated by S, in LUA we have the function table.concat () ( link ) It exists in various forms, namely:

--Sem separador
> = table.concat({ 1, 2, "three", 4, "five" })
12three4five
--Com separador
> = table.concat({ 1, 2, "three", 4, "five" }, ", ")
1, 2, three, 4, five
--Com separador e indice inicial inclusivo (indices em LUA começam em 1)
> = table.concat({ 1, 2, "three", 4, "five" }, ", ", 2)
2, three, 4, five
--Com separador, indice inicial e final (inclusivos)
> = table.concat({ 1, 2, "three", 4, "five" }, ", ", 2, 4)
2, three, 4

Source: link Note that this function does not work for nested tables

    
14.10.2015 / 17:07