Giter Site home page Giter Site logo

Use LÖVE's love.math.random when available about lume HOT 4 OPEN

rxi avatar rxi commented on September 27, 2024
Use LÖVE's love.math.random when available

from lume.

Comments (4)

jaythomas avatar jaythomas commented on September 27, 2024

Just a question in ignorance as I don't know the difference between the functions, but what's the reason to use love's math function as an override? Additionally, shouldn't that be an override you set outside of the lume library rather than expecting lume itself to be aware of another library being present?

from lume.

EntranceJew avatar EntranceJew commented on September 27, 2024

@jaythomas love.math.random and love in its entirety is meant to be cross-platform, whereas lua's math.random can vary by platform. This can complicate situations where two games are sharing a random seed and generating information or making decisions side-by-side. @slime73 knows better than me, though.

from lume.

jaythomas avatar jaythomas commented on September 27, 2024

Thanks, @EntranceJew. That answers my first question.

The reason I asked the second question is because my concern is that by making it the library's responsibility to have an awareness of love's random function, you are introducing a bias towards using this library in conjunction with love. As a user of this library, I may be using lume inside a service where love is not defined globally, or perhaps I'm not using love at all. Personally, I think it makes more sense to implement a "mixin" function where you can register new functions or override existing top-level functions like math_random. Psuedo code:

  lume.mixin('math_random', love.math.random)

This way if I wanted to use a completely different random function, or if love decided to move the random function somewhere else, the library wouldn't care. Not its job to be responsible for other librarys' APIs.

Again, just my opinion.

from lume.

rxi avatar rxi commented on September 27, 2024

Agreeing with several for @jaythomas's points, mainly:

... my concern is that by making it the library's responsibility to have an awareness of love's random function, you are introducing a bias towards using this library in conjunction with love.

So I won't be including this, nor merging the corresponding pull request (#13).

That being said, I do like the idea of supporting a mechanism for the user to supply their own random() function. I'm aware of the short comings of Lua's math.random(), on Windows, for example, last time I checked its implementation of rand() would return a 15bit integer which is at best not ideal.

I'll have to think about the best way to go about this (in terms of naming, and exactly how the provided random() function is expected to act) before adding it in.

from lume.

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.