forked from qt-creator/qt-creator
Lua: Allow clearing an aspects MacroExpander
Adds a value "Null" to simpletypes to allow setting null values in Tables: Settings.BoolAspect.create({ -- ... macroExpander = Null }) Adds Macro.globalExpander() to retrieve the global expander. Changes the result of MacroExpander.value() to (ok, value). Change-Id: I2e2577b8d2f6acd447a3701f7ecaf835504768da Reviewed-by: <lie@spyro-soft.com> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -12,12 +12,28 @@ void setupMacroModule()
|
||||
registerProvider("Macro", [](sol::state_view lua) {
|
||||
sol::table module = lua.create_table();
|
||||
|
||||
module.set_function("expand", [](const QString &s) -> QString {
|
||||
module.new_usertype<Utils::MacroExpander>(
|
||||
"MacroExpander",
|
||||
sol::no_constructor,
|
||||
"expand",
|
||||
[](Utils::MacroExpander *self, const QString &str) { return self->expand(str); },
|
||||
"value",
|
||||
[](Utils::MacroExpander *self, const QByteArray &str) {
|
||||
bool found = false;
|
||||
const QString res = self->value(str, &found);
|
||||
return std::make_pair(found, res);
|
||||
});
|
||||
|
||||
module.set_function("globalExpander", [] { return Utils::globalMacroExpander(); });
|
||||
|
||||
module.set_function("expand", [](const QString &s) {
|
||||
return Utils::globalMacroExpander()->expand(s);
|
||||
});
|
||||
|
||||
module.set_function("value", [](const QString &s) -> QString {
|
||||
return Utils::globalMacroExpander()->value(s.toUtf8());
|
||||
module.set_function("value", [](const QString &s) {
|
||||
bool found = false;
|
||||
const QString res = Utils::globalMacroExpander()->value(s.toUtf8(), &found);
|
||||
return std::make_pair(found, res);
|
||||
});
|
||||
|
||||
return module;
|
||||
|
@@ -112,7 +112,12 @@ void baseAspectCreate(BaseAspect *aspect, const std::string &key, const sol::obj
|
||||
[func = value.as<sol::function>()] { void_safe_call(func); });
|
||||
} else if (key == "enabler")
|
||||
aspect->setEnabler(value.as<BoolAspect *>());
|
||||
else
|
||||
else if (key == "macroExpander") {
|
||||
if (value.is<Null>())
|
||||
aspect->setMacroExpander(nullptr);
|
||||
else
|
||||
aspect->setMacroExpander(value.as<MacroExpander *>());
|
||||
} else
|
||||
qWarning() << "Unknown key:" << key.c_str();
|
||||
}
|
||||
|
||||
|
@@ -421,6 +421,11 @@ void setupLuaEngine(QObject *guard)
|
||||
{
|
||||
QTC_ASSERT(!d, return);
|
||||
d = new LuaInterfaceImpl(guard);
|
||||
|
||||
autoRegister([](sol::state_view lua) {
|
||||
lua.new_usertype<Null>("NullType", sol::no_constructor);
|
||||
lua.set("Null", Null{});
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Lua
|
||||
|
@@ -109,4 +109,7 @@ sol::protected_function_result runFunction(
|
||||
|
||||
void setupLuaEngine(QObject *guard);
|
||||
|
||||
class Null
|
||||
{};
|
||||
|
||||
} // namespace Lua
|
||||
|
@@ -2,13 +2,34 @@
|
||||
-- SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
---@meta Macro
|
||||
|
||||
local macro = {}
|
||||
---@class MacroExpander
|
||||
local MacroExpander = {}
|
||||
|
||||
---Expands all variables in the given string.
|
||||
---@param stringWithVariables string The string with variables to expand.
|
||||
---@return string The expanded string.
|
||||
function MacroExpander:expand(stringWithVariables) end
|
||||
|
||||
---Returns the value of the given variable.
|
||||
---@param variableName string The name of the variable.
|
||||
---@return boolean ok Whether the variable was found.
|
||||
---@return string value The value of the variable.
|
||||
function MacroExpander:value(variableName) end
|
||||
|
||||
---Returns the global Macro expander
|
||||
---@return MacroExpander
|
||||
function macro.globalExpander() end
|
||||
|
||||
---Returns globalExpander():value(variableName).
|
||||
---@param variableName string The name of the variable.
|
||||
---@return boolean ok Whether the variable was found.
|
||||
---@return string value The value of the variable.
|
||||
function macro.value(variableName) end
|
||||
|
||||
---Returns globalExpander():expand(stringWithVariables).
|
||||
---@param stringWithVariables string The string with variables to expand.
|
||||
---@return string The expanded string.
|
||||
function macro.expand(stringWithVariables) end
|
||||
|
||||
return macro
|
||||
|
@@ -1,6 +1,7 @@
|
||||
---@meta Settings
|
||||
|
||||
---@module 'Qt'
|
||||
---@module 'SimpleTypes'
|
||||
|
||||
local settings = {}
|
||||
|
||||
@@ -19,6 +20,7 @@ function settings.BaseAspect:apply() end
|
||||
---@field enabler? BoolAspect Enable / Disable this aspect based on the state of the `enabler`.
|
||||
---@field onValueChanged? function () Called when the value of the aspect changes.
|
||||
---@field onVolatileValueChanged? function () Called when the volatile value of the aspect changes.
|
||||
---@field macroExpander? MacroExpander|NullType The macro expander to use, or nil to disable macro expansion.
|
||||
local AspectCreate = {}
|
||||
|
||||
---The base class of most typed aspects.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
---@meta
|
||||
---@meta SimpleTypes
|
||||
|
||||
---@class QRect
|
||||
---@field x integer The x position of the rectangle.
|
||||
@@ -28,9 +28,19 @@ QPointF = {}
|
||||
---@field height number The height of the floating point size.
|
||||
QSizeF = {}
|
||||
|
||||
---@class QRectF
|
||||
---@class QRectF A rectangle with floating point coordinates.
|
||||
---@field x number The x position of the floating point rectangle.
|
||||
---@field y number The y position of the floating point rectangle.
|
||||
---@field width number The width of the floating point rectangle.
|
||||
---@field height number The height of the floating point rectangle.
|
||||
QRectF = {}
|
||||
|
||||
---@class NullType
|
||||
NullType = {}
|
||||
|
||||
---Just a workaround to let "Null" show the correct type in the documentation.
|
||||
---@return NullType null
|
||||
local function null() end
|
||||
|
||||
---A special object to represent a nullptr value.
|
||||
Null = null()
|
||||
|
Reference in New Issue
Block a user