Page 1 of 1

[Mod] Text / Code Editor [0.1][editor]

PostPosted: Sun Aug 28, 2016 14:32
by rubenwardy
Image

Flexible formspec based text editor for Minetest (with an API)

Version: 0.1
License: MIT
Dependencies: none
Download: https://github.com/rubenwardy/editor/archive/master.zip
Github: https://github.com/rubenwardy/editor

Report bugs or request help on the forum topic.

Secure virtual filesystem. The filesystem seen in the editor is not a real filesystem, but a simulated lua one.
Sample editor with persistence. Basic functionality such as a file list to open files,
tabs to switch between open files, close to close open files, and new to create new files.

This mod won't do anything by itself! You need to install a mod such as Insecure Lua Editor to actually use this mod's API

Installation



Unzip the archive, rename the folder to editor and
place it in minetest/mods/

( GNU/Linux: If you use a system-wide installation place
it in ~/.minetest/mods/. )

( If you only want this to be used in a single world, place
the folder in worldmods/ in your worlddirectory. )

For further information or help see:
http://wiki.minetest.com/wiki/Installing_Mods

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Sun Aug 28, 2016 15:59
by TheReaperKing
This is really neat! Do you have any recommendations of simple code my students and I could write in here so they could easily see the results of their work? I think print is great. Also I see you said the filesystem is virtual, is it possible to save it to a file? I suppose we could always copy and paste. Thanks so much for making this!

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Sun Aug 28, 2016 16:06
by rubenwardy
A player's filesystem is automatically saved to worlds/world/editor_files/playername.lua when they log out, or the server shuts down. It's in a lua table serialised format, like so:

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
return {
    version = 1,
    files = {
          ["path/to/file1.txt"] = "file1 content",
          ["path/to/file2.txt"] = "file2 content"
    }
}


This mod is good for a singleplayer world where they can try out interactive things. For example:

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
local player = minetest.get_player_by_name("singleplayer")
local pos = vector.round(player:getpos())

minetest.set_node(pos, { name = "nyancat:nyancat" })


will place nyancat nodes at the player's feet when ran

PostPosted: Sun Aug 28, 2016 17:43
by Hybrid Dog
Unfortunately the current multiline formspec text field is extremely inconvenient and it does not likely change (https://github.com/minetest/minetest/pull/3474), so your efforts are for the cat.

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Sun Aug 28, 2016 18:26
by rubenwardy
Nope, you can just fix that in the engine. And if we add a syntax text box we can do that. This is better than no editor.

PostPosted: Mon Aug 29, 2016 13:16
by Hybrid Dog
rubenwardy wrote:This is better than no editor.

You're right.
Anyway, l need a file browser mod.

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Sat Oct 01, 2016 23:47
by twoelk
Indeed a nice file browser to explore some folder structures might be very useful. It could be used as plugin or api for such mods as WE or any other mod that needs to load and save content to a folder structure. It would be cool if for example I could organize my schematics in several folders or even some central common folder at minetest root outside of the world folder. This way I could easily share files between worlds without having to copy them around.

Could this be used to access real unsimulated other text files of other mods such as those used by the wiki mod, the gutenberg mod or some server guide mods from within the game?

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Sat Oct 01, 2016 23:49
by rubenwardy
It could, if you change filesystem.lua to use real file system functions

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Tue Oct 04, 2016 04:16
by TG-MyinaWD
If I'm looking at this right.. You can create a mod ingame?

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Tue Oct 04, 2016 08:55
by rubenwardy
No, it's an editor that can execute lua code

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Sun Dec 04, 2016 17:48
by sorcerykid
I think there should a lot more emphasis in the description about the vulnerabilities of executing untrusted Lua code (i.e. tainted code). The loadstring( ) function is inherently insecure, and allows would-be attackers to inject arbitrary and dangerous code at runtime, which could seriously compromise the Minetest server (and potentially even the operating system itself), including changing passwords, deleting files, hanging the process, invoking shell commands, etc.

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Sun Dec 04, 2016 18:16
by rubenwardy
Wrong topic - the mod you're talking about is insecure lua editor (the clue is in the name). Both mods are a work in progress, the aim it to make it an editor eventually to be used to run sandboxed Lua code on the server to control turtle bots

Re: [Mod] Text / Code Editor [0.1][editor]

PostPosted: Sun Dec 04, 2016 19:27
by hajo
rubenwardy wrote:Image
Flexible formspec based text editor for Minetest (with an API)
..
Secure virtual filesystem. .. not a real filesystem, but a simulated lua one.
Sample editor with persistence.

Could this be used to edit books ?

As in, filename==>book-title, text==>book-contents,
where each file resides in one of the player's books.
Maybe with bookshelves as directories.

Also, a monospaced font and scrollbars would be nice,
as well as a counter telling the current line
(e.g. for finding the source of "error in line 27").
Or a button that prepends each line of text with a linenumber
(but editor and language-processor need to agree on how to count lines).

BTW, why have that line of filename-tabs at the top,
as well as that column at the left ?
A statusline for the current file, and the buttons for new/save/run etc.
would use the space better.