luan for loop syntax?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

luan for loop syntax?

Will
I'm trying to do a for loop in luan, but got syntax errors.

Code is like this

        local bullets = parseBullets(html)
        for _, b in bullets do
                newHtml = newHtml .. "<li>" .. b .. "</li>"
        end

Bullets is an array

error is:

Internel Server Error

attempt to call a table value
        site:/ai.js.luan line 291 in function 'workSubBulletAdd'
        site:/ai.js.luan line 308
Reply | Threaded
Open this post in threaded view
|

Re: luan for loop syntax?

Will
I changed to use the following and works.

        for i in range (1, #bullets) do
                newHtml = newHtml .. "<li>" .. bullets[i] .. "</li>"
        end
Reply | Threaded
Open this post in threaded view
|

Re: luan for loop syntax?

fschmidt
Administrator
Better is:
	for _, b in ipairs(bullets) do 
		newHtml = newHtml .. "<li>" .. b .. "</li>" 
	end