Page 1 of 1

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

Posted: Mon Sep 14, 2020 4:48 pm
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 )

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

Posted: Tue Sep 15, 2020 10:50 am
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

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

Posted: Tue Sep 15, 2020 1:46 pm
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.

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

Posted: Tue Sep 15, 2020 3:36 pm
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

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

Posted: Wed Sep 16, 2020 10:23 pm
by qwdqwqwffqw
Understood. Your clarifications are really helpful. Thanks again!

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

Posted: Sat Feb 13, 2021 9:14 pm
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?

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

Posted: Sat Feb 13, 2021 11:06 pm
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.

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

Posted: Sat Feb 13, 2021 11:27 pm
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.