2023-04-23 08:39:54 +00:00
|
|
|
#ifndef _SCRIPT_H_
|
|
|
|
|
#define _SCRIPT_H_
|
|
|
|
|
|
|
|
|
|
#include "runtime.h"
|
|
|
|
|
#include "core/stream/stream.h"
|
|
|
|
|
#include "module.h"
|
2023-06-02 14:36:04 +00:00
|
|
|
#include "core/util/tDictionary.h"
|
2023-04-23 08:39:54 +00:00
|
|
|
|
|
|
|
|
namespace Con
|
|
|
|
|
{
|
|
|
|
|
inline EvalResult gLastEvalResult;
|
|
|
|
|
inline EvalResult setLastEvalResult(EvalResult pLastEvalResult)
|
|
|
|
|
{
|
|
|
|
|
gLastEvalResult.valid = pLastEvalResult.valid;
|
|
|
|
|
gLastEvalResult.error = pLastEvalResult.error;
|
|
|
|
|
gLastEvalResult.value.setString(pLastEvalResult.value.getString());
|
2024-03-18 18:13:00 +00:00
|
|
|
return pLastEvalResult;
|
2023-04-23 08:39:54 +00:00
|
|
|
}
|
|
|
|
|
inline EvalResult getLastEvalResult() { return setLastEvalResult(std::move(gLastEvalResult)); };
|
|
|
|
|
|
|
|
|
|
bool runStream(Stream* byteCode, const char* fileName);
|
|
|
|
|
|
|
|
|
|
bool isCurrentScriptToolScript();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Module* getCurrentModule();
|
|
|
|
|
|
2023-06-02 14:36:04 +00:00
|
|
|
inline HashMap<S32, Runtime*> gRuntimes;
|
2023-04-23 08:39:54 +00:00
|
|
|
inline Runtime* getRuntime(S32 pRuntimeId = 0) { return gRuntimes[pRuntimeId]; }
|
|
|
|
|
inline void registerRuntime(S32 pRuntimeId, Runtime* pRuntime)
|
|
|
|
|
{
|
|
|
|
|
AssertFatal(gRuntimes[pRuntimeId] == NULL, "A runtime with that ID already exists");
|
|
|
|
|
gRuntimes[pRuntimeId] = pRuntime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Evaluate an arbitrary chunk of code.
|
|
|
|
|
///
|
|
|
|
|
/// @param script Buffer containing code to execute.
|
|
|
|
|
/// @param echo Should we echo the string to the console?
|
|
|
|
|
/// @param fileName Indicate what file this code is coming from; used in error reporting and such.
|
|
|
|
|
/// NOTE: This function restores the console stack on return.
|
|
|
|
|
inline EvalResult evaluate(const char* script, bool echo = false, const char *fileName = NULL) { return setLastEvalResult(getRuntime()->evaluate(script, echo, fileName)); };
|
|
|
|
|
|
|
|
|
|
inline EvalResult evaluate(const char* script, S32 frame, bool echo = false, const char *fileName = NULL) { return setLastEvalResult(getRuntime()->evaluate(script, frame, echo, fileName)); };
|
|
|
|
|
|
|
|
|
|
/// Evaluate an arbitrary line of script.
|
|
|
|
|
///
|
|
|
|
|
/// This wraps dVsprintf(), so you can substitute parameters into the code being executed.
|
|
|
|
|
/// NOTE: This function restores the console stack on return.
|
|
|
|
|
inline EvalResult evaluatef(const char* string, ...)
|
|
|
|
|
{
|
2023-09-16 22:22:44 +00:00
|
|
|
char buffer[4096];
|
2023-04-23 08:39:54 +00:00
|
|
|
va_list args;
|
2024-07-22 19:59:48 +00:00
|
|
|
va_start(args, string);
|
2023-09-16 22:22:44 +00:00
|
|
|
dVsprintf(buffer, sizeof(buffer), string, args);
|
2023-04-23 08:39:54 +00:00
|
|
|
va_end(args);
|
2023-09-16 22:22:44 +00:00
|
|
|
|
|
|
|
|
EvalResult result = setLastEvalResult(getRuntime()->evaluate(buffer));
|
2023-04-23 08:39:54 +00:00
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Executes a script file and compiles it for use in script.
|
|
|
|
|
///
|
|
|
|
|
/// @param string File name that is the script to be executed and compiled.
|
|
|
|
|
/// @param fileName Path to the file to execute
|
|
|
|
|
/// @param noCalls Deprecated
|
|
|
|
|
/// @param journalScript Deprecated
|
|
|
|
|
///
|
|
|
|
|
/// @return True if the script was successfully executed, false if not.
|
|
|
|
|
inline bool executeFile(const char* fileName, bool noCalls, bool journalScript) { return getRuntime()->executeFile(fileName, noCalls, journalScript); };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|