mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
stuff
This commit is contained in:
parent
478e9bef17
commit
a70fee4d35
8 changed files with 44 additions and 53 deletions
|
@ -232,6 +232,14 @@ if core.set_read_node and core.set_push_node then
|
|||
core.set_read_node = nil
|
||||
|
||||
local function push_node(content, param1, param2)
|
||||
if false then -- TODO: tmp
|
||||
print(dump(debug.traceback()))
|
||||
--~ error()
|
||||
for i = 0, 10 do
|
||||
print("i="..i)
|
||||
print(dump(debug.getinfo(i)))
|
||||
end
|
||||
end
|
||||
return {name = content2name[content], param1 = param1, param2 = param2}
|
||||
end
|
||||
core.set_push_node(push_node)
|
||||
|
|
|
@ -7,7 +7,28 @@ local mypath = scriptpath .. "sscsm_client".. DIR_DELIM
|
|||
-- not exposed to outer context
|
||||
local builtin_shared = {}
|
||||
|
||||
-- placeholders
|
||||
-- FIXME: send actual content defs to sscsm env
|
||||
function core.get_content_id(name)
|
||||
return tonumber(name)
|
||||
end
|
||||
function core.get_name_from_content_id(id)
|
||||
return tostring(id)
|
||||
end
|
||||
|
||||
assert(loadfile(commonpath .. "item_s.lua"))(builtin_shared)
|
||||
assert(loadfile(commonpath .. "register.lua"))(builtin_shared)
|
||||
assert(loadfile(mypath .. "register.lua"))(builtin_shared)
|
||||
|
||||
dofile(commonpath .. "after.lua")
|
||||
|
||||
|
||||
-- TODO: tmp
|
||||
|
||||
local function dings()
|
||||
print(dump(core.get_node_or_nil(vector.zero())))
|
||||
core.after(1, dings)
|
||||
end
|
||||
--~ core.after(0, dings)
|
||||
|
||||
print(core.get_current_modname())
|
||||
|
|
|
@ -171,6 +171,8 @@ Client::Client(
|
|||
event1->files.emplace_back("sscsm_test0:init.lua",
|
||||
R"=+=(
|
||||
print("sscsm_test0: loading")
|
||||
--print(dump(_G))
|
||||
--print(debug.traceback())
|
||||
)=+=");
|
||||
m_sscsm_controller->runEvent(this, std::move(event1));
|
||||
|
||||
|
|
|
@ -421,7 +421,7 @@ void ScriptApiSecurity::initializeSecuritySSCSM()
|
|||
};
|
||||
static const char *debug_whitelist[] = {
|
||||
"getinfo", // used by builtin and unset before mods load //TODO
|
||||
"traceback" //TODO
|
||||
"traceback" //TODO: is this fine, or does it print paths of C functions?
|
||||
};
|
||||
|
||||
#if USE_LUAJIT
|
||||
|
@ -488,6 +488,8 @@ void ScriptApiSecurity::initializeSecuritySSCSM()
|
|||
|
||||
// Set the environment to the one we created earlier
|
||||
setLuaEnv(L, thread);
|
||||
|
||||
// TODO: tostring({})
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -284,12 +284,16 @@ int ModApiClient::l_get_privilege_list(lua_State *L)
|
|||
// get_builtin_path()
|
||||
int ModApiClient::l_get_builtin_path(lua_State *L)
|
||||
{
|
||||
std::string modname;
|
||||
if (getScriptApiBase(L)->getType() == ScriptingType::Client)
|
||||
lua_pushstring(L, BUILTIN_MOD_NAME ":");
|
||||
modname = BUILTIN_MOD_NAME;
|
||||
else if (getScriptApiBase(L)->getType() == ScriptingType::SSCSM)
|
||||
lua_pushstring(L, "*client_builtin*:"); //TODO
|
||||
else
|
||||
modname = ScriptApiBase::getCurrentModNameInsecure(L);
|
||||
|
||||
if (modname.empty())
|
||||
return 0;
|
||||
|
||||
lua_pushstring(L, (modname + ":").c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,51 +7,8 @@
|
|||
#include "common/c_content.h"
|
||||
#include "common/c_converter.h"
|
||||
#include "l_internal.h"
|
||||
#include "log.h"
|
||||
#include "script/sscsm/sscsm_environment.h"
|
||||
#include "script/sscsm/sscsm_requests.h"
|
||||
#include "mapnode.h"
|
||||
|
||||
// print(text)
|
||||
int ModApiSSCSM::l_print(lua_State *L) //TODO: not core.print
|
||||
{
|
||||
auto request = SSCSMRequestPrint{};
|
||||
request.text = luaL_checkstring(L, 1);
|
||||
getSSCSMEnv(L)->doRequest(std::move(request));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// log([level], text)
|
||||
int ModApiSSCSM::l_log(lua_State *L)
|
||||
{
|
||||
/*
|
||||
auto request = SSCSMRequestLog{};
|
||||
request.text = luaL_checkstring(L, 1);
|
||||
getSSCSMEnv(L)->doRequest(std::move(request));
|
||||
|
||||
std::string_view text;
|
||||
LogLevel level = LL_NONE;
|
||||
if (lua_isnoneornil(L, 2)) {
|
||||
text = readParam<std::string_view>(L, 1);
|
||||
} else {
|
||||
auto name = readParam<std::string_view>(L, 1);
|
||||
text = readParam<std::string_view>(L, 2);
|
||||
// if (name == "deprecated") { //TODO
|
||||
// log_deprecated(L, text, 2);
|
||||
// return 0;
|
||||
// }
|
||||
level = Logger::stringToLevel(name);
|
||||
if (level == LL_MAX) {
|
||||
warningstream << "Tried to log at unknown level '" << name
|
||||
<< "'. Defaulting to \"none\"." << std::endl;
|
||||
level = LL_WARNING;
|
||||
}
|
||||
}
|
||||
g_logger.log(level, text);
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get_node_or_nil(pos)
|
||||
// pos = {x=num, y=num, z=num}
|
||||
|
@ -76,7 +33,5 @@ int ModApiSSCSM::l_get_node_or_nil(lua_State *L)
|
|||
|
||||
void ModApiSSCSM::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(print);
|
||||
API_FCT(log);
|
||||
API_FCT(get_node_or_nil);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "lua_api/l_client.h"
|
||||
|
||||
SSCSMScripting::SSCSMScripting(SSCSMEnvironment *env) :
|
||||
ScriptApiBase(ScriptingType::SSCSM) //TODO: use different CUSTOM_RIDX_ERROR_HANDLER, or set debug.traceback
|
||||
ScriptApiBase(ScriptingType::SSCSM)
|
||||
{
|
||||
setSSCSMEnv(env);
|
||||
|
||||
|
@ -27,8 +27,6 @@ SSCSMScripting::SSCSMScripting(SSCSMEnvironment *env) :
|
|||
// Push builtin initialization type
|
||||
lua_pushstring(L, "sscsm");
|
||||
lua_setglobal(L, "INIT");
|
||||
|
||||
// infostream << "SCRIPTAPI: Initialized SSCSM modules" << std::endl;
|
||||
}
|
||||
|
||||
void SSCSMScripting::initializeModApi(lua_State *L, int top)
|
||||
|
|
|
@ -43,6 +43,7 @@ struct SSCSMRequestSetFatalError : public ISSCSMRequest
|
|||
};
|
||||
|
||||
// print(text)
|
||||
// FIXME: override global loggers to use this in sscsm process
|
||||
struct SSCSMRequestPrint : public ISSCSMRequest
|
||||
{
|
||||
struct Answer : public ISSCSMAnswer
|
||||
|
@ -73,7 +74,7 @@ struct SSCSMRequestLog : public ISSCSMRequest
|
|||
SerializedSSCSMAnswer exec(Client *client) override
|
||||
{
|
||||
if (level >= LL_MAX) {
|
||||
errorstream << "Tried to log at non-existent level." << std::endl; // TODO: should probably throw
|
||||
throw BaseException("Tried to log at non-existent level."); // TODO: choose better exception type
|
||||
} else {
|
||||
g_logger.log(level, text);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue