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

Lua tables that contains objects are not rendered with pongo2 #119

Open
usernope opened this issue Aug 18, 2022 · 13 comments
Open

Lua tables that contains objects are not rendered with pongo2 #119

usernope opened this issue Aug 18, 2022 · 13 comments
Labels
bug This is a bug can-reproduce-the-issue Can reproduce the issue lua Related to the Lua programming language pongo2 Related to the Pongo2 templates

Comments

@usernope
Copy link

I'm using algernon to try to output data from a lua script into a pongo2 template.

In the code below number_list outputs exactly as I'd expect but nothing renders for object_list.

What am I doing wrong?

data.lua

title = "This is the title"

number_list = {}

table.insert(number_list, 1)
table.insert(number_list, 2)
table.insert(number_list, 3)

object_list = {}

o1 = {1}
table.insert(object_list, o1)
o2 = {2}
table.insert(object_list, o2)
o3 = {3}
table.insert(object_list, o3)

index.po2

<html>
  <head>
    <title>{{title}}</title>
  </head>
  <body>
    {{ title }}
    <div>

        {% for item in number_list %}
        test 1: {{item}} 
        {% endfor %}

        {% for item in object_list %}
        test 2: {{item}}
        {% endfor %}

    </div>
  </body>
</html>
@xyproto
Copy link
Owner

xyproto commented Aug 18, 2022

Thanks for reporting! I'll look into this.

@xyproto xyproto self-assigned this Aug 18, 2022
@xyproto xyproto added planning-to-reproduce-the-issue Planning to reproduce the issue lua Related to the Lua programming language pongo2 Related to the Pongo2 templates labels Aug 18, 2022
@tooolbox
Copy link
Collaborator

@usernope what is your expected output? <object> or some such?

If the output is really blank, Algernon's only failing is probably that it does not output <object> or <table> or similar.

@usernope
Copy link
Author

usernope commented Aug 19, 2022

@tooolbox I've tried it with just the text "test2" and it doesn't render it.

object_list seems to have a length of 0.

@tooolbox
Copy link
Collaborator

Ah, so the output contains no instances of the text test 2:

Interesting.

This, or approximately this, was working as of #79 so perhaps some kind of regression.

@usernope
Copy link
Author

Hi, I'd just like to check if anyone has managed to reproduce the problem or if it's something on my side.

Thanks.

@tooolbox
Copy link
Collaborator

tooolbox commented Aug 20, 2022

I reproduced with the latest release on Windows. Straight sequences and key-value tables work fine, but nesting a table makes the length zero. Also checked with {{ object_list | length }}

I had a suspicion which turned out to be true, though:

I don't use data.lua because I don't like polluting the global VM space, I use an index.lua that calls serve2 with a page.tmpl and that works fine (just tested). So the issue appears to be with the data.lua feature specifically. @usernope maybe try changing to a Lua handler as a workaround while this is otherwise investigated?

@xyproto xyproto added can-reproduce-the-issue Can reproduce the issue bug This is a bug and removed planning-to-reproduce-the-issue Planning to reproduce the issue labels Aug 20, 2022
@xyproto xyproto removed their assignment Aug 20, 2022
@usernope
Copy link
Author

Thanks @tooolbox serve2 seems to work with pongo2 for now.

@xyproto
Copy link
Owner

xyproto commented Aug 26, 2022

@usernope

If I place data.lua and index.po2 in a directory and launch Algernon with algernon -e . or algernon -t ., it seems to work fine.

I get:

This is the title
test 1: 2 test 1: 3 test 1: 1

Could you please let me know:

  • If you using Algernon from the main branch, or the latest release version?
  • Which command are you using for launching Algernon?

@tooolbox Does this appear to work on Windows when using the latest main commit?

@xyproto xyproto added trying-to-reproduce-the-issue Not able to reproduce the issue yet waiting-for-a-reply Waiting for a reply or clarification from the submitter of the issue and removed bug This is a bug can-reproduce-the-issue Can reproduce the issue labels Aug 26, 2022
@tooolbox
Copy link
Collaborator

tooolbox commented Aug 27, 2022

Hey @xyproto I believe the problem is the output should look roughly like this:

This is the title
test 1: 2 test 1: 3 test 1: 1
test 2: <table> test 2: <table> test 2: <table>

But you just get this:

This is the title
test 1: 2 test 1: 3 test 1: 1

The whole second loop generates no output and if you do {{ object_list | length }} the result is zero.

I tested and repro'd with latest release rather than latest commit, because I don't actually have a Go compiler on this windows box, long story 😅 But, quickly scanning over the interim commit messages, I don't see anything that would seem to affect this?

@xyproto xyproto added bug This is a bug can-reproduce-the-issue Can reproduce the issue and removed waiting-for-a-reply Waiting for a reply or clarification from the submitter of the issue trying-to-reproduce-the-issue Not able to reproduce the issue yet labels Aug 27, 2022
xyproto added a commit that referenced this issue Apr 20, 2023
@xyproto
Copy link
Owner

xyproto commented Apr 21, 2023

When adding some logging to Algernon, for what the Lua state contains, I get this:

INFO[3816] GOT <nil>: o2 ==> map[1:2] (map[int]int)
INFO[3816] GOT <nil>: number_list ==> map[1:1 2:2 3:3] (map[int]int)
INFO[3816] GOT <nil>: o1 ==> map[1:1] (map[int]int)
INFO[3816] GOT <nil>: _G ==> map[_GOPHER_LUA_VERSION:GopherLua 0.1 _VERSION:Lua 5.1 title:This is the title] (map[string]string)
INFO[3816] GOT <nil>: math ==> map[huge:9223372036854775807 pi:3] (map[string]int)
INFO[3816] GOT <nil>: o3 ==> map[1:3] (map[int]int)

It looks like number_list is fine, and is considered to be a map[int]int, while object_list is interpreted as o1, o2and o3, for some reason.

I wonder if this could be an issue with the Lua interpreter, or if maps of objects just needs to be handled in a different way within Algernon. I'll check the type of object_list.

@xyproto
Copy link
Owner

xyproto commented Apr 24, 2023

I think the "next action" here might be to switch to a different Lua implementation.

@tooolbox
Copy link
Collaborator

I think the "next action" here might be to switch to a different Lua implementation.

Oh my!

Well, is it really the Lua implementation, or is the implementation of the data.lua feature? Because as I noted above, it works fine when using an index.lua handler:

I don't use data.lua because I don't like polluting the global VM space, I use an index.lua that calls serve2 with a page.tmpl and that works fine (just tested). So the issue appears to be with the data.lua feature specifically. @usernope maybe try changing to a Lua handler as a workaround while this is otherwise investigated?

Just something to check into before you need to go to those lengths, I think.

@xyproto
Copy link
Owner

xyproto commented Apr 25, 2023

You are right. I think my comment was a bit rushed.

There is also #126, thought, that I am contemplating how to resolve without changing the Lua implementation.

@xyproto xyproto changed the title Lua table not rendering in pongo2 Lua tables that contains objects are not rendered with pongo2 May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug can-reproduce-the-issue Can reproduce the issue lua Related to the Lua programming language pongo2 Related to the Pongo2 templates
Projects
None yet
Development

No branches or pull requests

3 participants