How to use --unsafe-scripts?

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
dwarftough
Posts: 300
Joined: August 4th, 2019, 5:27 pm

How to use --unsafe-scripts?

Post by dwarftough »

Hi! I found in man wesnoth that there is --unsafe-scripts option. It says "--unsafe-scripts makes the package package available to lua scripts, so that they can load arbitrary packages."

Can somebody guide me what exactly it unlocks and how would be possible to use, let's say, file io if this is enabled? I wanted to make a testing addon for me to carry experiments in Wesnoth, and arranging file io right from the lua code would be a nice addition to that
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
User avatar
Celtic_Minstrel
Developer
Posts: 1929
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: How to use --unsafe-scripts?

Post by Celtic_Minstrel »

Unfortunately, it doesn't expose the io module (although arguably it probably should). All it does is add a require global function, which will allow you to load binary Lua modules written in C or modules installed on your system. It's disabled by default because it would allow an addon to execute arbitrary code on your computer.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
dwarftough
Posts: 300
Joined: August 4th, 2019, 5:27 pm

Re: How to use --unsafe-scripts?

Post by dwarftough »

Celtic_Minstrel wrote: June 29th, 2022, 2:13 am Unfortunately, it doesn't expose the io module (although arguably it probably should). All it does is add a require global function, which will allow you to load binary Lua modules written in C or modules installed on your system. It's disabled by default because it would allow an addon to execute arbitrary code on your computer.
Would I be able then to compile io as a C lib and require it then?
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
User avatar
Celtic_Minstrel
Developer
Posts: 1929
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: How to use --unsafe-scripts?

Post by Celtic_Minstrel »

I guess? I can't guarantee it'll work cleanly, as Wesnoth's build of Lua is slightly customized, so errors in C libs built for standard Lua might crash the program in the worst case… but I have no reason to believe it wouldn't work at all. And if you're building it yourself anyway you could just apply the same customizations that Wesnoth does.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
Post Reply