[Solved] List of lua functions which are not for cross-platform?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
qwdqwqwffqw
Prole
Posts: 15
Joined: Sat Jan 25, 2020 4:11 pm

[Solved] List of lua functions which are not for cross-platform?

Post by qwdqwqwffqw »

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 )
Last edited by qwdqwqwffqw on Wed Sep 16, 2020 10:22 pm, edited 1 time in total.
User avatar
zorg
Party member
Posts: 3282
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: List of lua functions which are not for cross-platform?

Post by zorg »

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
Me and my stuff :3True 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.
qwdqwqwffqw
Prole
Posts: 15
Joined: Sat Jan 25, 2020 4:11 pm

Re: List of lua functions which are not for cross-platform?

Post by qwdqwqwffqw »

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.
User avatar
zorg
Party member
Posts: 3282
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: List of lua functions which are not for cross-platform?

Post by zorg »

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. :3
Me and my stuff :3True 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.
qwdqwqwffqw
Prole
Posts: 15
Joined: Sat Jan 25, 2020 4:11 pm

Re: [Solved] List of lua functions which are not for cross-platform?

Post by qwdqwqwffqw »

Understood. Your clarifications are really helpful. Thanks again!
User avatar
ivan
Party member
Posts: 1822
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: List of lua functions which are not for cross-platform?

Post by ivan »

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.
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.
Also will string.dump work between 32/64 bit versions?
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: List of lua functions which are not for cross-platform?

Post by grump »

ivan wrote: Sat Feb 13, 2021 9:14 pm Also will string.dump work between 32/64 bit versions?
Bytecode is portable and can be loaded all architectures, but is tied to the LuaJIT version. If you can ensure the same LuaJIT version is used on every platform, then there should be no problem.
User avatar
ivan
Party member
Posts: 1822
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: [Solved] List of lua functions which are not for cross-platform?

Post by ivan »

Ok so this is great. Did some testing and it's notecably faster to load bytecode compared to regular Lua or even minified Lua.
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests