Coder Social home page Coder Social logo

Comments (6)

seabadger avatar seabadger commented on May 19, 2024

Correction: looks like all keys are accessible with pairs(), and only non-negative are accessible via ipairs().

So this is only a little inconsistent, and may catch people if they either try to access the data using ipairs(), or if they try to use something that accesses tables in a generic way (e.g., the output above was produced via https://github.com/kikito/inspect.lua).

Thus, maybe not a bug, but a possible usability problem. I understand you may want to keep it the way it is, but I'll keep the report open just in case you have other thoughts.

from lua-protobuf.

starwing avatar starwing commented on May 19, 2024

Thanks for catching! But it’s really a bug. I will fix on next push (maybe tonight)

from lua-protobuf.

starwing avatar starwing commented on May 19, 2024

After a carefully review code and review your post, I'm very sorry I misunderstand your issue before :-(

Yes, it's not a bug. in Lua, { "one", "two" } is exactly just { [1] = "one", [2] = "two" }, and former is just a syntax sugar of latter.

and map's semantics indicate no order. means { [1] = "one", [2] = "two" } or { [2] = "two", [1] = "one" } are all legal result of decode.

from lua-protobuf.

starwing avatar starwing commented on May 19, 2024

Notice that's the semantics of Lua language. So I have no way to change this behavior :-)

just close, if you have new idea about map, you can re-open it. Thanks for feedback!

from lua-protobuf.

seabadger avatar seabadger commented on May 19, 2024

I agree that this is semantics of Lua and not really a bug (thanks for taking a look anyway! :).
It might still be worth mentioning this in the documentation that map keys, even when they are integers, should be accessed via 'pairs()' only, not ipairs() (since the latter might not give the full set of keys). I know it's just the language semantics, but it's one of the less obvious bits that might catch someone.

from lua-protobuf.

starwing avatar starwing commented on May 19, 2024

Okay I will change document :-)

from lua-protobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.