Hi guys.
To my knowledge, most of built-in lua functions and standard library functions work just fine even after those lua files are converted into packages(.love, .exe, android apps, etc)
However, some functions from i/o library and operating system library do not for various reasons.
Is there any organized list of those functions which shouldn't be used for cross-platform LÖVE projects? ( I could find out some instances from search but couldn't find a complete list )
[Solved] List of lua functions which are not for cross-platform?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 24
- Joined: Sat Jan 25, 2020 4:11 pm
[Solved] List of lua functions which are not for cross-platform?
Last edited by qwdqwqwffqw on Wed Sep 16, 2020 10:22 pm, edited 1 time in total.
- zorg
- Party member
- Posts: 3449
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: List of lua functions which are not for cross-platform?
Everything that's in the love. table/namespace behaves accordingly to what is said on the wiki. Most of them is in fact cross-platform, since that was a goal for Löve. (including love.filesystem, use that and not lua's io; note it is sandboxed, but there are libraries that solve that issue...)
As for lua itself, these would be best avoided:
- dofile, loadfile (not loadstring or load), the whole io library, os.remove, os.rename, os.tmpname -> due to the fact that paths can behave differently on different OS-es. one exception: with some editors, to have console output, you need to do io.setvbuf('no').
- module (if it even exists in the version löve uses) -> module is deprecated, just use tables and require.
- string.dump -> you can use it, but i'd only recommend it to be used for the same instance of the project you're running; e.g. copying functions over love.threads... even that is not without caveats; anyway, different OS-es might have löve use different lua(jit) versions so dumped functions might differ in what string they return, making them not compatible.
- math.random, math.randomseed -> since löve uses luajit, this should be safe to use (it doesn't use OS-specific backends), but using love.math.random is preferred due to the fact luajit could potentially also change how its PRNG works.
- os.getenv might return different things depending on the OS, but they will work technically; löve gives you a way to detect what OS it's running on, so you could potentially work around this.
Finally, to be a bit pedantic, even floating point math can be implemented differently per-architecture, so i could say "don't use lua numbers period", but that'd be silly... there are solutions for this too, though.
Also, if you are on windows, that does not distinguish letter case in paths, but all other OS-es, and even zip does, so do take care to have your cases be correct, otherwise stuff will randomly break even with love.filesystem stuff if you zip up your project and rename it to .love
As for lua itself, these would be best avoided:
- dofile, loadfile (not loadstring or load), the whole io library, os.remove, os.rename, os.tmpname -> due to the fact that paths can behave differently on different OS-es. one exception: with some editors, to have console output, you need to do io.setvbuf('no').
- module (if it even exists in the version löve uses) -> module is deprecated, just use tables and require.
- string.dump -> you can use it, but i'd only recommend it to be used for the same instance of the project you're running; e.g. copying functions over love.threads... even that is not without caveats; anyway, different OS-es might have löve use different lua(jit) versions so dumped functions might differ in what string they return, making them not compatible.
- math.random, math.randomseed -> since löve uses luajit, this should be safe to use (it doesn't use OS-specific backends), but using love.math.random is preferred due to the fact luajit could potentially also change how its PRNG works.
- os.getenv might return different things depending on the OS, but they will work technically; löve gives you a way to detect what OS it's running on, so you could potentially work around this.
Finally, to be a bit pedantic, even floating point math can be implemented differently per-architecture, so i could say "don't use lua numbers period", but that'd be silly... there are solutions for this too, though.
Also, if you are on windows, that does not distinguish letter case in paths, but all other OS-es, and even zip does, so do take care to have your cases be correct, otherwise stuff will randomly break even with love.filesystem stuff if you zip up your project and rename it to .love
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
-
- Prole
- Posts: 24
- Joined: Sat Jan 25, 2020 4:11 pm
Re: List of lua functions which are not for cross-platform?
This answer is exactly what i was looking for. Many thanks!!
One more question :
Is there anything I should be cautious when using 'setfenv()' and 'getfenv()' functions? As they are for changing environment, I'm worried if they might act weird in different system.
- I'm not assuming players' (potentially risky) access to modifying code or offering anything like sandbox features; I'm just asking about things I should be aware of when I code with environment-related feaures in love/lua generally.
One more question :
Is there anything I should be cautious when using 'setfenv()' and 'getfenv()' functions? As they are for changing environment, I'm worried if they might act weird in different system.
- I'm not assuming players' (potentially risky) access to modifying code or offering anything like sandbox features; I'm just asking about things I should be aware of when I code with environment-related feaures in love/lua generally.
- zorg
- Party member
- Posts: 3449
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: List of lua functions which are not for cross-platform?
set/get fenv modifies the function environment for a code chunk, not the OS's environment; that said, indeed it can be used to redefine the _G global table for specific environments.
tbh idk how to answer the second part other than make sure to not allow things that could be used for malicious behaviour... there are quite a few things that encompass, but some might be needed anyway even if they could be used for malicious things... not that you can excise keywords like `for`, or whatever.
tbh idk how to answer the second part other than make sure to not allow things that could be used for malicious behaviour... there are quite a few things that encompass, but some might be needed anyway even if they could be used for malicious things... not that you can excise keywords like `for`, or whatever.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
-
- Prole
- Posts: 24
- Joined: Sat Jan 25, 2020 4:11 pm
Re: [Solved] List of lua functions which are not for cross-platform?
Understood. Your clarifications are really helpful. Thanks again!
Re: List of lua functions which are not for cross-platform?
Hey Zorg. Suppose I am distributing the game binaries myself across platforms and I make sure they all have the same version of LuaJIT packaged along.zorg wrote: ↑Tue Sep 15, 2020 10:50 am - string.dump -> you can use it, but i'd only recommend it to be used for the same instance of the project you're running; e.g. copying functions over love.threads... even that is not without caveats; anyway, different OS-es might have löve use different lua(jit) versions so dumped functions might differ in what string they return, making them not compatible.
Also will string.dump work between 32/64 bit versions?
Re: [Solved] List of lua functions which are not for cross-platform?
Ok so this is great. Did some testing and it's notecably faster to load bytecode compared to regular Lua or even minified Lua.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests