Giter Club home page Giter Club logo

Comments (9)

rrthomas avatar rrthomas commented on July 28, 2024

lua_objlen does indeed push its result on the stack.

As far as I can see, the error here is in the documentation: the phrase "(in Lua >= 5.2)" should be moved to after "userdata".

from lrexlib.

shmuz avatar shmuz commented on July 28, 2024

lua_objlen does indeed push its result on the stack.

Both the Lua 5.1 manual and a simple experiment show that it is not true.

As far as I can see, the error here is in the documentation: the phrase "(in Lua >= 5.2)" should be moved to after "userdata".

Do you mean the feature is not supported for Lua 5.1 ?

from lrexlib.

rrthomas avatar rrthomas commented on July 28, 2024

Sorry, I misread the manual. No, I mean that the feature is not supported for userdata in Lua 5.1. In Lua 5.1 a push should be added to put the length on the stack.

from lrexlib.

rrthomas avatar rrthomas commented on July 28, 2024

Thanks for adding support for userdata in Lua 5.1, and well done for fixing the error message as well!

Looking at your fix, it seems it now won't work on plain tables in Lua 5.1. Wouldn't it be better simply to lift the restriction in the documentation, and call lua_objlen when the argument is a table without a __len metamethod?

Also, please can you not put patches for different purposes into the same commit.

from lrexlib.

shmuz avatar shmuz commented on July 28, 2024

Looking at your fix, it seems it now won't work on plain tables in Lua 5.1.

Do you mean that prior to my fix it did work on plain tables in Lua 5.1 ?

Wouldn't it be better simply to lift the restriction in the documentation, and call lua_objlen when the argument is a table without a __len metamethod?

Maybe. Personally I don't need table-subjects such as described above. If you do, please implement it.

from lrexlib.

rrthomas avatar rrthomas commented on July 28, 2024

I meant that it would have worked had you simply added a push. The extra fix is small, so it seems hardly worth not making it just to complicate the documentation and make the behaviour different between Lua 5.1 and 5.2. I'll do it.

from lrexlib.

rrthomas avatar rrthomas commented on July 28, 2024

Fixed. I also noticed that for Lua 5.2 I could use luaL_len, so the code is now actually slightly shorter than before.

from lrexlib.

shmuz avatar shmuz commented on July 28, 2024

I meant that it would have worked had you simply added a push. The extra fix is small, so it seems hardly worth not making it just to complicate the documentation and make the behaviour different between Lua 5.1 and 5.2. I'll do it.

Unfortunately I still fail to understand how the length of the table's array part in Lua 5.1 can meaningfully serve as the length of the subject.

The only case that comes to my mind is the table containing an array of single characters, but it seems to be a very specific case not justifying allowing of a table as the subject.

from lrexlib.

rrthomas avatar rrthomas commented on July 28, 2024

I'm just trying to make the behaviour the same in Lua 5.1 and 5.2, not decide whether it was sensible, but I see I've failed in any case, since now the Lua 5.1 code doesn't look for a __len metamethod on tables. I've made a change so that it does so.

It would probably have taken less of your time if you'd made this fix, not me!

from lrexlib.

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.