19#ifndef jwlua_fflua_luascriptitem_h
20#define jwlua_fflua_luascriptitem_h
24#include <unordered_map>
72 std::string _filepath;
73 std::string _filename;
74 std::optional<std::string> _scripttext;
75 std::string _menutext;
76 std::string _undotext;
77 std::string _description;
79 std::unordered_map<std::string, std::string> _fields;
83 bool _versionCompatible;
84 bool _autoReportErrors;
87 EVERSION _minFinaleYear;
88 EVERSION _maxFinaleYear;
89 EVERSION _minFinaleVersion;
90 EVERSION _maxFinaleVersion;
91 EVERSION _minLuaVersion;
92 EVERSION _maxLuaVersion;
102 luabridge::LuaRef _printCallBack;
103 luabridge::LuaRef _handleExecutionStarted;
104 luabridge::LuaRef _handleExecutionStopped;
105 luabridge::LuaRef _handleModalWindowOpened;
106 luabridge::LuaRef _handleModalWindowClosed;
111 _loadasstring =
false;
112 _versionCompatible =
false;
113 _autoReportErrors =
true;
116 _maxFinaleYear = UINT32_MAX;
117 _minFinaleVersion = 0;
118 _maxFinaleVersion = UINT32_MAX;
120 _maxLuaVersion = UINT32_MAX;
122 _controllingwindow =
nullptr;
125 template<
typename... Args>
126 void ExecuteCallbackFunction(luabridge::LuaRef& functionLuaRef, Args... args)
128 if (functionLuaRef.isFunction())
129 functionLuaRef(
this, args...);
133#ifndef DOXYGEN_SHOULD_IGNORE_THIS
143 : _cleanupFunction(cleanupFunc), _isExecuting(isExecutingFunc), _executableindex(-1),
145 _handleExecutionStarted(L),
146 _handleExecutionStopped(L),
147 _handleModalWindowOpened(L),
148 _handleModalWindowClosed(L)
152 _filepath = filePath;
154 _filename = fileName;
155 assert(!_filepath.size() || _filename.size());
157 _scripttext = scriptText;
167 : _cleanupFunction(
nullptr), _isExecuting(isExecuting), _executableindex(index),
169 _handleExecutionStarted(L),
170 _handleExecutionStopped(L),
171 _handleModalWindowOpened(L),
172 _handleModalWindowClosed(L)
176 _filename = fileName;
193 _handleExecutionStarted = luabridge::LuaRef(_handleExecutionStarted.state());
194 _handleExecutionStopped = luabridge::LuaRef(_handleExecutionStopped.state());
195 if (_cleanupFunction) _cleanupFunction(
this);
199 const char*
ClassName()
const override {
return "FCLuaScriptItem"; }
288 if (_scripttext.has_value())
289 return _scripttext->c_str();
315 const char *
GetPrefix()
const {
return _prefix.c_str(); }
372 throw std::runtime_error(
"Invalid value passed to FCLuaScriptItem::GetRequiredVersion");
413 auto it = _fields.find(fieldname);
414 if (it == _fields.end())
416 return new FCString(it->second.c_str());
419#ifndef DOXYGEN_SHOULD_IGNORE_THIS
420 luabridge::RefCountedPtr<FCString> CreateFinalePluginValue_GC(
const char *fieldname)
442 _scripttext = std::nullopt;
527 if (!lua_callback_function.isFunction())
return false;
528 _printCallBack = lua_callback_function;
544 if (!lua_callback_function.isFunction())
return false;
545 _handleExecutionStarted = lua_callback_function;
561 if (!lua_callback_function.isFunction())
return false;
562 _handleExecutionStopped = lua_callback_function;
581 if (!lua_callback_function.isFunction())
return false;
582 _handleModalWindowOpened = lua_callback_function;
598 if (!lua_callback_function.isFunction())
return false;
599 _handleModalWindowClosed = lua_callback_function;
609 ExecuteCallbackFunction(_handleExecutionStarted);
624 void OnExecutionDidStop(
bool success,
const char* msg,
int msgtype,
int linenumber,
const char* source)
626 ExecuteCallbackFunction(_handleExecutionStopped, success, msg, msgtype, linenumber, source);
635 ExecuteCallbackFunction(_handleModalWindowOpened);
648 ExecuteCallbackFunction(_handleModalWindowClosed);
651#ifndef DOXYGEN_SHOULD_IGNORE_THIS
653 const luabridge::LuaRef& GetPrintFunction()
const {
return _printCallBack; }
656 void SetVersionCompatible(
const bool state) { _versionCompatible = state; }
659 void SetFinalePluginFields(
const std::unordered_map<std::string, std::string>& fields)
660 { _fields = fields; }
668 _minFinaleVersion = requiredversion;
672 _maxFinaleVersion = requiredversion;
676 _minFinaleYear = requiredversion;
680 _maxFinaleYear = requiredversion;
684 _minLuaVersion = requiredversion;
688 _maxLuaVersion = requiredversion;
692 throw std::runtime_error(
"Invalid value passed to FCLuaScriptItem::SetRequiredVersion");
715 const char*
ClassName()
const override {
return "FCLuaScriptItems"; }
Base class for the Finale Framework classes.
Definition ff_base.h:71
void SetUserData(void *pData)
Sets the user data attached to the instance of an object.
Definition ff_base.h:503
void * GetUserData() const
Gets the user data attached to the instance of an object.
Definition ff_base.h:517
Base class for all collection classes. A collection is a storage that can store multiple objects of s...
Definition ff_basecollection.h:26
void Add(__FCBase *pNewItem)
Adds an element to the end of the collection.
Definition finaleframework.cpp:13726
__FCBase * GetItemAt(int index) const
Returns the object at the index position. Index is 0-based.
Definition finaleframework.cpp:13767
void InsertItemAt(__FCBase *pNewItem, int index)
Inserts an item into the collection.
Definition finaleframework.cpp:13733
Base class for all other dialog/window classes.
Definition ff_dialogs.h:563
Class that represents a single Lua script item. This class is not part of the C++ PDK Framework.
Definition fflua_luascriptitem.h:70
bool GetAutomaticallyReportErrors() const
Gets if errors should automatically be reported by the Lua connector. The default value is true.
Definition fflua_luascriptitem.h:379
bool GetTrusted() const
Gets if the script should run in trusted mode. Default is false.
Definition fflua_luascriptitem.h:385
void StopExecuting()
Stops execution and terminates the Lua state.
Definition fflua_luascriptitem.h:240
void SetUndoText(const char *value)
Sets the undo text for the script.
Definition fflua_luascriptitem.h:455
void SetOptionalScriptText(const char *value)
Sets the optional script text.
Definition fflua_luascriptitem.h:437
void SetDebug(bool state)
Sets if the script should be run in debug mode.
Definition fflua_luascriptitem.h:473
const char * GetMenuItemText() const
Returns the menu item text for the script.
Definition fflua_luascriptitem.h:297
bool RegisterPrintFunction(luabridge::LuaRef lua_callback_function)
Registers a Lua function that replaces called script's print function.
Definition fflua_luascriptitem.h:525
LUASCRIPT_REQVERSION_TYPES
Settings used to get required version information for a script.
Definition fflua_luascriptitem.h:206
@ REQVERSIONTYPE_MAXIMUM_LUAX1000
Definition fflua_luascriptitem.h:224
@ REQVERSIONTYPE_MINIMUM_LUAX1000
Definition fflua_luascriptitem.h:221
@ REQVERSIONTYPE_MAXIMUM_FINALE
Definition fflua_luascriptitem.h:212
@ REQVERSIONTYPE_MINIMUM_FINALE_MAJOR
Definition fflua_luascriptitem.h:215
@ REQVERSIONTYPE_MINIMUM_FINALE
Definition fflua_luascriptitem.h:209
@ REQVERSIONTYPE_MAXIMUM_FINALE_MAJOR
Definition fflua_luascriptitem.h:218
bool RegisterOnExecutionWillStart(luabridge::LuaRef lua_callback_function)
Registers a Lua function that gets called when the script item starts executing. For the function to ...
Definition fflua_luascriptitem.h:542
void OnModalWindowWillOpen()
Function that is called when the script execution will open a modal dialog.
Definition fflua_luascriptitem.h:633
bool RegisterOnModalWindowWillOpen(luabridge::LuaRef lua_callback_function)
Registers a Lua function that gets called when the script item opens a modal dialog....
Definition fflua_luascriptitem.h:579
void SetDescription(const char *value)
Sets the description for the script.
Definition fflua_luascriptitem.h:461
void SetPrefix(const char *value)
Sets the prefix for the script.
Definition fflua_luascriptitem.h:467
void SetMenuItemText(const char *value)
Sets the menu item text for the script.
Definition fflua_luascriptitem.h:449
bool RegisterOnExecutionDidStop(luabridge::LuaRef lua_callback_function)
Registers a Lua function that gets called when the script item stops executing. For the function to b...
Definition fflua_luascriptitem.h:559
bool GetDebug() const
Return true if the script should be run in debug mode.
Definition fflua_luascriptitem.h:321
void OnExecutionWillStart()
Function that is called when script execution starts.
Definition fflua_luascriptitem.h:607
const char * GetPrefix() const
Returns the prefix for the script.
Definition fflua_luascriptitem.h:315
bool IsExecuting() const
Returns true if the script associated with this script item is currently executing.
Definition fflua_luascriptitem.h:232
__FCUserWindow * GetControllingWindow() const
Gets the controlling window for this script item.
Definition fflua_luascriptitem.h:400
void SetTrusted(bool state)
Sets if the script should run in trusted mode. If you set this to true, the script that calls finenv....
Definition fflua_luascriptitem.h:496
const char * GetFilePath() const
Returns the fully-qualified file path for the script or empty string if none.
Definition fflua_luascriptitem.h:253
const char * GetUndoText() const
Returns the undo text for the script.
Definition fflua_luascriptitem.h:303
bool GetVersionCompatible() const
If false, this script is not compatible with either the running Finale or the running Lua plugin vers...
Definition fflua_luascriptitem.h:352
const char * ClassName() const override
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition fflua_luascriptitem.h:199
FCString * CreateFinalePluginValue(const char *fieldname)
Return the requested finaleplugin value.
Definition fflua_luascriptitem.h:411
const char * GetOptionalScriptText() const
Returns the optional script text.
Definition fflua_luascriptitem.h:286
int GetExecutableIndex() const
Returns the executable index for this script.
Definition fflua_luascriptitem.h:341
void OnExecutionDidStop(bool success, const char *msg, int msgtype, int linenumber, const char *source)
Function that is called when script execution stops and its Lua state is closed.
Definition fflua_luascriptitem.h:624
void SetControllingWindow(__FCUserWindow *value)
Sets the controlling window for this script item.
Definition fflua_luascriptitem.h:509
bool GetLoadAsString() const
Return true if the script should be loaded as a string.
Definition fflua_luascriptitem.h:332
void SetAutomaticallyReportErrors(bool state)
Sets if errors should automatically be reported by the Lua connector. The default value is true.
Definition fflua_luascriptitem.h:488
void SetLoadAsString(bool state)
Sets if the script should be loaded as a string.
Definition fflua_luascriptitem.h:482
bool RegisterOnModalWindowDidClose(luabridge::LuaRef lua_callback_function)
Registers a Lua function that gets called when the script item closes a modal dialog....
Definition fflua_luascriptitem.h:596
EVERSION GetRequiredVersion(int versiontype) const
Returns a required version number from one of the LUASCRIPT_REQVERSION_TYPES constants.
Definition fflua_luascriptitem.h:361
const char * GetFileName() const
Returns the file name of the script or empty string if none.
Definition fflua_luascriptitem.h:263
void OnModalWindowDidClose()
Function that is called when the script execution has closed a modal dialog.
Definition fflua_luascriptitem.h:646
const char * GetDescription() const
Returns the description for the script.
Definition fflua_luascriptitem.h:309
A collection of FCLuaScriptItem members.
Definition fflua_luascriptitem.h:713
FCLuaScriptItem * GetItemAt(int index) const
Overridden GetItemAt() method that returns an FCLuaScriptItem object.
Definition fflua_luascriptitem.h:740
FCLuaScriptItems()
The constructor.
Definition fflua_luascriptitem.h:721
const char * ClassName() const override
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition fflua_luascriptitem.h:715
void Add(FCLuaScriptItem *pNewItem)
Overridden Add() method that takes an FCLuaScriptItem object.
Definition fflua_luascriptitem.h:728
void InsertItemAt(FCLuaScriptItem *pNewItem, int index)
Overridden InsertItemAt() method that takes an FCLuaScriptItem object.
Definition fflua_luascriptitem.h:734
Class that provides storage for text. This is to achieve platform-transparent text handling,...
Definition ff_base.h:1877