Can't get script working

Hello, I’m a new user (one day old) and I’d like to get a function working in my pages.
Let me know if this is not the spot to post these questions!

I added the following function within a page, and tried to call it with ${transform_calorie_text(...)}, which didn’t really work (function is still nil). Am I supposed to do something more to make the function available? Do I have to declare this somewhere else?

function transform_calorie_text(text)
    local result = {}

    for line in text:gmatch("[^\r\n]+") do
        local before, inside = line:match("^(.-)%((.-)%)$")
        if before and inside then
            inside = inside:gsub("c", "")
            before = before:gsub("%s*$", "")
            table.insert(result, before .. "\t=" .. inside)
        end
    end

    return table.concat(result, "\n")
end
1 Like

if you haven’t already, run the System: Reload command

1 Like

Nope, doesn’t help

1 Like

it’s the “\t=” space-lua doesnt seems to recognise it.

you can see the red marker there, that means something is wrong with the syntax. If you wanted to add the literal tab character, try this:

table.insert(result, before .. string.char(9) .. "=" .. inside)

1 Like

Ah, I didn’t realize. I tried this on another lua interpreter and it was ok. Thanks for the help!

1 Like

Caused by bug. Fix PR-ed.

1 Like

Just merged it, should be available on the edge builds soon.

1 Like

that’s great! thanks a lot @mjf @zef

1 Like