Git Product home page Git Product logo

Comments (3)

gvvaughan avatar gvvaughan commented on June 26, 2024

Thanks for the feedback.

Lua 5.1 stored all numbers (integers or floats) as 53 bit IEEE 754 doubles. More recent Lua releases including 5.4, but I forget when exactly, added real low level integer types. luaposix tries to work correctly with Lua 5.1 and newer, including luajit, within the constraints of the various apis exposed by each, but misses some corner cases in doing that.

Your suggestion uses a call that is not supported by Lua 5.1 and would prevent luaposix compiling there.

I thing passing a floating point number to getpwuid is not really sensible (even though older Lua interpreters will store it as a float internally) because UNIX uids are always integers -- there is no uid 1001.25! Better to change your code to pwd.getpwuid(0) IMHO.

Nonetheless, if you find a way to reliably force integer equivalent floats to real integers that works on luajit and Lua 5.1+ that is not too torturous, please do submit a PR.

from luaposix.

emberfade avatar emberfade commented on June 26, 2024

Thank you for your thorough answer.

Your suggestion uses a call that is not supported by Lua 5.1 and would prevent luaposix compiling there.

Are your referring to lua_tointegerx? I compiled luaposix with the suggestion for 5.1 and it works with Lua 5.1 and LuaJIT. What I did see is that LuaJIT, 5.1 and 5.2 would accept 1000.25, the others didn't. But that seems to be the same behaviour as now, if I tested this correctly.

The code in

lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) {
lua_Integer n = lua_tointeger(L, i);
if (isnum != NULL) {
*isnum = (n != 0 || lua_isnumber(L, i));
}
return n;
}

gives lua_tointegerx which I think is included, if LUA_VERSION_NUM == 501. Would that be sufficient for 5.1?

I thing passing a floating point number to getpwuid is not really sensible (even though older Lua interpreters will store it as a float internally) because UNIX uids are always integers -- there is no uid 1001.25! Better to change your code to pwd.getpwuid(0) IMHO.

I do agree. It shouldn't be problem to use math.tointeger(). It was just really unfortunate that the behaviour changed and only for that one case.

Nonetheless, if you find a way to reliably force integer equivalent floats to real integers that works on luajit and Lua 5.1+ that is not too torturous,

Could you perhaps test my suggestion and see if it works for you as well? Hopefully, I didn't make a mistake compiling for 5.1

from luaposix.

gvvaughan avatar gvvaughan commented on June 26, 2024

I totally spaced on the compat code, and you are quite right! Let me see if I can merge this later today. Thanks for persevering with me 😁

from luaposix.

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.