Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
borcut opened this issue Jun 29, 2018 · 0 comments
Open

Comments

@borcut
Copy link

borcut commented Jun 29, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant