working external load
This commit is contained in:
parent
7b9112ad6e
commit
4018d9b9cf
1
init.lua
1
init.lua
@ -11,4 +11,5 @@ dofile(MP .. "/context/cube.lua")
|
||||
dofile(MP .. "/context/grid.lua")
|
||||
dofile(MP .. "/context/slope.lua")
|
||||
dofile(MP .. "/util.lua")
|
||||
dofile(MP .. "/load.lua")
|
||||
dofile(MP .. "/test.lua")
|
27
load.lua
Normal file
27
load.lua
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
local path = minetest.get_worldpath() .. "/mtscad"
|
||||
minetest.mkdir(path)
|
||||
|
||||
minetest.register_chatcommand("scad", {
|
||||
func = function(name, filename)
|
||||
local def, load_err = loadfile(path .. "/" .. filename)
|
||||
if not def then
|
||||
return false, "Loading failed with '" .. load_err .. "'"
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local ppos = player:get_pos()
|
||||
local ctx = mtscad.create_context(vector.round(ppos))
|
||||
|
||||
local success, exec_err = pcall(function()
|
||||
local fn = def()
|
||||
fn(ctx)
|
||||
end)
|
||||
|
||||
if not success then
|
||||
return false, "Execute failed with '" ..exec_err .. "'"
|
||||
end
|
||||
|
||||
return true, "File successfully executed"
|
||||
end
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user