Cuberite Forum
Change the working directory of a function or coroutine - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Change the working directory of a function or coroutine (/thread-1998.html)



Change the working directory of a function or coroutine - NiLSPACE - 06-06-2015

Does anyone know how to change the working directory for a function?
The idea is that if inside that function for example the "dofile" or "cFile:Exists" function is used it doesn't direct to "root/<asked file>" but "root/Plugins/MC-Web-Server/www/<asked file>"


RE: Change the working directory of a function or coroutine - worktycho - 06-06-2015

I hope this isn't possible. The working directory is process global, so the change would effect other plugins in strange ways.

What are you actually trying to do? It looks like re-implement nginx's ngx_lua module. Why? MCServer's HTTP support is crap, and really should be farmed out to an actual server.


RE: Change the working directory of a function or coroutine - worktycho - 06-06-2015

Off topic, but I really don't like the idea of a custom HTTP server. I've looked through your code, and already noticed that it doesn't handle uri encoding, and it has a path traversal vulnerability, as you don't pass a deliminator to StringSplit on host.lua line 25. Make sure you also handle \ for the path to fix problems on windows.


RE: Change the working directory of a function or coroutine - NiLSPACE - 06-06-2015

(06-06-2015, 09:37 AM)worktycho Wrote: I hope this isn't possible. The working directory is process global, so the change would effect other plugins in strange ways.
I'm wondering what dofile is doing then. When you use for example: 'dofile("folder1/folder2/file1.lua")' then everything in file1.lua is executed in folder1/folder2.

But it turns out I have to rewrite those functions anyway, because I have to make them parse the file first.

worktycho Wrote:Off topic, but I really don't like the idea of a custom HTTP server. I've looked through your code, and already noticed that it doesn't handle uri encoding, and it has a path traversal vulnerability, as you don't pass a deliminator to StringSplit on host.lua line 25. Make sure you also handle \ for the path to fix problems on windows.
Of course, this is just me having fun with browsers and seeing how they work ^^