Skip to content

Fail to render sections: attempt to call method 'lookup' (a nil value). #37

@borcut

Description

@borcut

Tested on Windows 10 with lustache 1.3.1-0 and Lua 5.1.5.

While trying to render some of the examples from the readme I got the following error:

lua: .\lustache.lua:404: attempt to call method 'lookup' (a nil value)
stack traceback:
        .\lustache.lua:404: in function '_name'
        .\lustache.lua:202: in function <.\lustache.lua:188>
        (tail call): ?
        .\lustache.lua:347: in function '_section'
        .\lustache.lua:194: in function <.\lustache.lua:188>
        (tail call): ?
        (tail call): ?
        test-lustache-sections.lua:18: in main chunk
        [C]: ?

The test file was

local lustache = require "lustache"
local view_model, template

view_model = {
  stooges = {
    { name = "Moe" },
    { name = "Larry" },
    { name = "Curly" },
  }
}

template = [[
{{#stooges}}
* {{name}}
{{/stooges}}
]]

print(lustache:render(template, view_model))

The first bug I found was in the function Context:lookup(name), where the call to string_find interprets "." as a pattern (search any character). The line

if string_find(name, ".") > 0 then

should be changed to

if string_find(name, ".", 1, true) then

The second bug is when the function Context:new(view, parent) sets the wrong metatable when called from Renderer:_section(token, context, callback, originalTemplate). My workaround was to change the two callback(context:push(v), self) calls into callback(Context:push(v), self).

lustache-sections.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions