io.lines() seems not longer to work

User avatar
addi
Member
 
Posts: 605
Joined: Thu Sep 20, 2012 03:16

io.lines() seems not longer to work

by addi » Sun Nov 06, 2016 09:58

Some time ago I have written a mod like the clean mod.
The difference to pilzAdams clean mod is, that it fetches the unknown nodes from a txt file (each line contains 1 node) and uses a abm
It worked great in Minetest 0.4.14 but it stopped working in some dev version.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Clean mod 2.1
--
-- (c) 2016 King Arthurs Team

local old_nodes = {}

local MODNAME = minetest.get_current_modname()
local MODPATH = minetest.get_modpath(MODNAME)
local file = MODPATH..DIR_DELIM.."unknown-nodes.txt"
for node_name in io.lines(file) do
    table.insert(old_nodes, node_name:trim())
end

minetest.register_lbm({
        name = MODNAME..":old_nodes",
        nodenames = old_nodes,
    --  ^ List of node names to trigger the LBM on.
    --    Also non-registered nodes will work.
    --    Groups (as of group:groupname) will work as well.
        run_at_every_load = true,
    --  ^ Whether to run the LBM's action every time a block gets loaded,
    --    and not just for blocks that were saved last time before LBMs were
    --    introduced to the world.
        action = minetest.remove_node
    })

https://www.lua.org/manual/5.1/manual.html#pdf-io.lines

The error message I get is the following:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
2016-11-06 10:43:09: ERROR[Main]: ModError: Failed to load and run script from ...\init.lua:
2016-11-06 10:43:09: ERROR[Main]: .../clean.lua:10: attempt to call a nil value
2016-11-06 10:43:09: ERROR[Main]: stack traceback:
2016-11-06 10:43:09: ERROR[Main]:    .../clean.lua:10: in main chunk
2016-11-06 10:43:09: ERROR[Main]: Check debug.txt for details.


line 10 is for node_name in io.lines(file) do
Got the io.lines() removed for some reason? How to re-add the function?
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: io.lines() seems not longer to work

by rubenwardy » Sun Nov 06, 2016 12:24

This was caused by the default enabling of mod security sandbox. Not sure how to fix without implementing io.lines yourself
 

User avatar
addi
Member
 
Posts: 605
Joined: Thu Sep 20, 2012 03:16

Re: io.lines() seems not longer to work

by addi » Sun Nov 06, 2016 12:36

Its not not a good idea to re implement existing functions and work around security features. So I created an issue for it: https://github.com/minetest/minetest/issues/4741
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: io.lines() seems not longer to work

by BrandonReese » Mon Nov 07, 2016 14:13

You can open the file and then use filehandle:lines(). I fixed the io violations in some mods on my server but then I got tired of tracking down security violations and just turned it off.

In minetest.conf secure.enable_security = false

https://github.com/minetest/minetest/bl ... mple#L1510
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: io.lines() seems not longer to work

by Wuzzy » Tue Nov 08, 2016 14:12

There is a very good reason why mod security was enabled. Allowing mods to do everything on your machine is a very bad idea unless you know exactly what they do. Don't try to destroy this from the start by inventing bad workarounds. Minetest and/or the mods need real fixes, like addi said. Otherwise all the work which went into the security system was for nothing.

Modders: Please read viewtopic.php?f=18&t=12471
I'm creating MineClone 2, a Minecraft clone for Minetest.
I made the Help modpack, adding in-game help to Minetest.
 

User avatar
addi
Member
 
Posts: 605
Joined: Thu Sep 20, 2012 03:16

Re: io.lines() seems not longer to work

by addi » Wed Nov 09, 2016 10:25

Yes, the intention of the secure mode is correct, but currently its too buggy. A mod that works great with 0.4.14 schould also work with 0.4.15 and so on. (except it uses deprecated functions) else we would have the same bad behavior as minecraft. Shure modders can easily fix some functions. In this case io.lines(filename) could simply replaced by file:lines() and it would only require a few lines more. But we should also think about players that play the game with mods that does not have the knowlege how to mod or how to fix bugs in mods. They get a odd errormessage about a nil value and the modder is in some cases maybe not able to find out what happens there (because he uses 0.4.14 stable version) At least a better error message should be printed to the player and tell them correctly that the function is not longer aviable for some reason.

And for the modders minetest needs to deliver a modified doku of lua where is exactly described what (lua standard) functions are save to use, what functions does require insecure and what functions does require to turn secure off.

Another bug is, that if there is only one mod which requires the require() function for some reason (eg. irc), its not enough to put irc into trusted mods settings. You have to turn off secure for all mods.

So minetest.conf secure.enable_security = false is the only solution imo
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: io.lines() seems not longer to work

by Wuzzy » Wed Nov 09, 2016 13:39

No, the real solution is to fix Minetest. :P As far I know, the next release is not around the corner, so there's plenty of time to fix the remaining bugs.
For me it seems that io.lines should work even without mod security as long you are operating on files within mod or world directory, which is the case here. So yes, it's a bug.

Can you please post your new suggestions and new bug reports here (it makes them more visible to the core devs)?:

https://github.com/minetest/minetest/issues/

And I agree, the existing Lua API for this desperately needs more documentation, especially a list of forbidden functions.

We should generally not expect players to fix the bugs in Minetest or its mods. :P

Btw: It is not enough to add a mod to trusted mods, the insecure functions must be called within an “insecure environment”. Even trusted mods have to follow rules. Also, why are you complaining about the IRC mod? I thought this mod was already made compatible a long time ago. Or does it currently break as well? Then please report a bug to the devs of Minetest and the IRC mod.
I'm creating MineClone 2, a Minecraft clone for Minetest.
I made the Help modpack, adding in-game help to Minetest.
 

User avatar
addi
Member
 
Posts: 605
Joined: Thu Sep 20, 2012 03:16

Re: io.lines() seems not longer to work

by addi » Wed Nov 09, 2016 14:41

Wuzzy wrote: Also, why are you complaining about the IRC mod? I thought this mod was already made compatible a long time ago. Or does it currently break as well? Then please report a bug to the devs of Minetest and the IRC mod.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
2016-11-09 15:25:21: WARNING[Main]: NodeDefManager: Ignoring CONTENT_IGNORE redefinition
2016-11-09 15:25:21: WARNING[Main]: Undeclared global variable "module" accessed at /usr/share/lua/5.1/socket.lua:14
2016-11-09 15:25:21: ERROR[Main]: ModError: Failed to load and run script from /home/minetest/ftp/world/worldmods/irc/init.lua:
2016-11-09 15:25:21: ERROR[Main]: /usr/share/lua/5.1/socket.lua:14: attempt to call global 'module' (a nil value)
2016-11-09 15:25:21: ERROR[Main]: stack traceback:
2016-11-09 15:25:21: ERROR[Main]:    /usr/share/lua/5.1/socket.lua:14: in main chunk
2016-11-09 15:25:21: ERROR[Main]:    [C]: in function 'require'
2016-11-09 15:25:21: ERROR[Main]:    /home/minetest/ftp/world/worldmods/irc/irc/init.lua:1: in main chunk
2016-11-09 15:25:21: ERROR[Main]:    [C]: in function 'require'
2016-11-09 15:25:21: ERROR[Main]:    /home/minetest/ftp/world/worldmods/irc/init.lua:36: in main chunk

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
secure.trusted_mods = irc
secure.enable_security = true

sorry, but I'm currently too annoyed to give a normal, friendly, usefull report there. Also just secure.enable_security = false also gets rid of the error, so this problem is solved --- at least for me. Maybe its better I wait some days until I can write something more technical/friendly. >>:-(
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: io.lines() seems not longer to work

by kaeza » Thu Nov 10, 2016 00:42

addi wrote:sorry, but I'm currently too annoyed to give a normal, friendly, usefull report there. Also just secure.enable_security = false also gets rid of the error, so this problem is solved --- at least for me. Maybe its better I wait some days until I can write something more technical/friendly. >>:-(

You are lucky I find these kinds of questions (`io.lines`) interesting, otherwise I wouldn't have known about this.

I'm currently too annoyed to give a normal, friendly, useful response, so I will just complain in this completely unrelated topic and not fix the mod's code. Is that fine with you?
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: io.lines() seems not longer to work

by kaeza » Thu Nov 10, 2016 01:18

It seems Wuzzy was nice enough to post that as an issue in the proper place. Please continue discussion there or at least on the IRC mod topic.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
addi
Member
 
Posts: 605
Joined: Thu Sep 20, 2012 03:16

Re: io.lines() seems not longer to work

by addi » Thu Nov 10, 2016 12:38

*rofl* Thanks Wuzzy :)
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 50 guests

cron