working external load

This commit is contained in:
BuckarooBanzay 2022-03-27 10:10:37 +02:00
parent 7b9112ad6e
commit 4018d9b9cf
2 changed files with 28 additions and 0 deletions

View File

@ -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
View 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
})