function explode(div,str)
if (div == '') then
return nil
else
local pos,arr = 0,{}
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1))
pos = sp + 1
end
table.insert(arr,string.sub(str,pos))
return arr
end
end
local minetestpath = minetest.get_worldpath()
--> C:\Users\Christian\Desktop\Minetest\bin\..\worlds\Singleplayer
minetestpath = explode("\",minetestpath)
--> {"C:","Users","Christian","Desktop","Minetest","bin","..","worlds","Singleplayer"}
-- Now we remove the last four strings in the list and we have the minetest dir
minetestpath[table.getn(minetestpath) - 0] = nil
minetestpath[table.getn(minetestpath) - 1] = nil
minetestpath[table.getn(minetestpath) - 2] = nil
minetestpath[table.getn(minetestpath) - 3] = nil
--> {"C:","Users","Christian","Desktop","Minetest"}
-- Convert it to a string
minetestpath = table.concat(minetestpath,"\")
webdesigner97 wrote:See this function (ported from PHP to Lua):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
function explode(div,str)
if (div == '') then
return nil
else
local pos,arr = 0,{}
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1))
pos = sp + 1
end
table.insert(arr,string.sub(str,pos))
return arr
end
end
It splits a string (str) at every occurence of <div> and returns it as a list: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 minetestpath = minetest.get_worldpath()
--> C:\Users\Christian\Desktop\Minetest\bin\..\worlds\Singleplayer
minetestpath = explode("",minetestpath)
--> {"C:","Users","Christian","Desktop","Minetest","bin","..","worlds","Singleplayer"}
-- Now we remove the last four strings in the list and we have the minetest dir
minetestpath[table.getn(minetestpath) - 0] = nil
minetestpath[table.getn(minetestpath) - 1] = nil
minetestpath[table.getn(minetestpath) - 2] = nil
minetestpath[table.getn(minetestpath) - 3] = nil
--> {"C:","Users","Christian","Desktop","Minetest"}
-- Convert it to a string
minetestpath = table.concat(minetestpath,"")
This should work, but I didn't test it ;)
PilzAdam wrote:webdesigner97 wrote:See this function (ported from PHP to Lua):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
function explode(div,str)
if (div == '') then
return nil
else
local pos,arr = 0,{}
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1))
pos = sp + 1
end
table.insert(arr,string.sub(str,pos))
return arr
end
end
It splits a string (str) at every occurence of <div> and returns it as a list: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 minetestpath = minetest.get_worldpath()
--> C:\Users\Christian\Desktop\Minetest\bin\..\worlds\Singleplayer
minetestpath = explode("",minetestpath)
--> {"C:","Users","Christian","Desktop","Minetest","bin","..","worlds","Singleplayer"}
-- Now we remove the last four strings in the list and we have the minetest dir
minetestpath[table.getn(minetestpath) - 0] = nil
minetestpath[table.getn(minetestpath) - 1] = nil
minetestpath[table.getn(minetestpath) - 2] = nil
minetestpath[table.getn(minetestpath) - 3] = nil
--> {"C:","Users","Christian","Desktop","Minetest"}
-- Convert it to a string
minetestpath = table.concat(minetestpath,"")
This should work, but I didn't test it ;)
And why dont you use string:split()? https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L1046
webdesigner97 wrote:See this function (ported from PHP to Lua):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
function explode(div,str)
if (div == '') then
return nil
else
local pos,arr = 0,{}
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1))
pos = sp + 1
end
table.insert(arr,string.sub(str,pos))
return arr
end
end
It splits a string (str) at every occurence of <div> and returns it as a list: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 minetestpath = minetest.get_worldpath()
--> C:\Users\Christian\Desktop\Minetest\bin\..\worlds\Singleplayer
minetestpath = explode("",minetestpath)
--> {"C:","Users","Christian","Desktop","Minetest","bin","..","worlds","Singleplayer"}
-- Now we remove the last four strings in the list and we have the minetest dir
minetestpath[table.getn(minetestpath) - 0] = nil
minetestpath[table.getn(minetestpath) - 1] = nil
minetestpath[table.getn(minetestpath) - 2] = nil
minetestpath[table.getn(minetestpath) - 3] = nil
--> {"C:","Users","Christian","Desktop","Minetest"}
-- Convert it to a string
minetestpath = table.concat(minetestpath,"")
This should work, but I didn't test it ;)
kahrl wrote:Note that get_worldpath may at any point in the future collapse the "bin" and ".." parts, without warning. I think it already does if the world path was passed to minetest via the command line.
Users browsing this forum: No registered users and 5 guests