2020-03-22 00:45:04 +01:00
|
|
|
#pragma once
|
2016-06-17 02:15:02 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Core/Common.hpp"
|
2016-06-17 02:15:02 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
|
2021-01-30 07:51:39 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <sqratScript.h>
|
|
|
|
|
2016-06-17 02:15:02 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
class Core;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Hold a information about loaded scripts as it's contents and executable code.
|
|
|
|
*/
|
2021-07-03 18:46:39 +02:00
|
|
|
struct ScriptSrc
|
2016-06-17 02:15:02 +02:00
|
|
|
{
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
typedef std::vector< std::pair< uint32_t, uint32_t > > Line;
|
2016-06-17 02:15:02 +02:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2021-07-03 18:46:39 +02:00
|
|
|
Script mExec{}; // Reference to the script object.
|
|
|
|
Function mFunc{}; // Callback to invoke after script was executed.
|
|
|
|
String mPath{}; // Path to the script file.
|
|
|
|
String mData{}; // The contents of the script file.
|
|
|
|
Line mLine{}; // List of lines of code in the data.
|
|
|
|
bool mInfo{false}; // Whether this script contains line information.
|
|
|
|
bool mDelay{false}; // Don't execute immediately after compilation.
|
2016-06-17 02:15:02 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Read file contents and calculate information about the lines of code.
|
|
|
|
*/
|
|
|
|
void Process();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-18 19:29:28 +02:00
|
|
|
* Base constructor.
|
2016-06-17 02:15:02 +02:00
|
|
|
*/
|
2021-07-03 18:46:39 +02:00
|
|
|
explicit ScriptSrc(const String & path, Function & cb, bool delay = false, bool info = false);
|
2016-06-17 02:15:02 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
|
|
|
ScriptSrc(const ScriptSrc & o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move constructor.
|
|
|
|
*/
|
|
|
|
ScriptSrc(ScriptSrc && o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy assignment operator.
|
|
|
|
*/
|
|
|
|
ScriptSrc & operator = (const ScriptSrc & o) = default;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move assignment operator.
|
|
|
|
*/
|
|
|
|
ScriptSrc & operator = (ScriptSrc && o) = default;
|
|
|
|
|
2019-06-16 01:20:18 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
* Fetches a line from the code. Can also trim whitespace at the beginning.
|
2019-06-16 01:20:18 +02:00
|
|
|
*/
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_NODISCARD String FetchLine(size_t line, bool trim = true) const;
|
2016-06-17 02:15:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|