Leviathan  0.8.0.0
Leviathan game engine
Leviathan::ScriptModule Class Reference

#include <ScriptModule.h>

+ Inheritance diagram for Leviathan::ScriptModule:

Public Member Functions

DLLEXPORT ScriptModule (asIScriptEngine *engine, const std::string &name, int id, const std::string &source)
 
DLLEXPORT ~ScriptModule ()
 
DLLEXPORT void SetAccessMask (AccessFlags access)
 Sets the access mask to be used for this script. More...
 
DLLEXPORT void AddAccessRight (AccessFlags newaccess)
 Adds flags to the AccessMask. More...
 
DLLEXPORT asIScriptModule * GetModule (Lock &guard)
 Builds the script if applicable. More...
 
DLLEXPORT asIScriptModule * GetModule ()
 
DLLEXPORT std::shared_ptr< ScriptScriptGetScriptInstance ()
 
DLLEXPORT std::string GetName ()
 
DLLEXPORT void Release ()
 Releases the internal resources. More...
 
DLLEXPORT const std::string & GetModuleName () const
 Gets the name of the internal AngelScript module. More...
 
DLLEXPORT int GetID ()
 
DLLEXPORT const std::string & GetSource () const
 
DLLEXPORT const std::string & GetIncompleteSourceCode ()
 
DLLEXPORT void DeleteThisModule ()
 
DLLEXPORT bool DoesListenersContainSpecificListener (const std::string &listenername, const std::string *generictype=NULL)
 
DLLEXPORT void GetListOfListeners (std::vector< std::shared_ptr< ValidListenerData >> &receiver)
 
DLLEXPORT std::string GetListeningFunctionName (const std::string &listenername, const std::string *generictype=NULL)
 
DLLEXPORT std::string GetInfoString ()
 
DLLEXPORT void SetBuildState (const SCRIPTBUILDSTATE &state)
 
DLLEXPORT size_t GetScriptSegmentCount () const
 Gets the number of code segments. More...
 
DLLEXPORT std::shared_ptr< ScriptSourceFileDataGetScriptSegment (size_t index) const
 Gets the data associated with a code segment. More...
 
DLLEXPORT FORCE_INLINE bool AddScriptSegment (const std::string &file, int line, const std::string &code)
 Adds a new script section. More...
 
DLLEXPORT bool AddScriptSegment (std::shared_ptr< ScriptSourceFileData > data)
 The actual implementation of AddScriptSegment. More...
 
DLLEXPORT bool AddScriptSegmentFromFile (const std::string &file)
 Adds an entire file as a script segment. More...
 
DLLEXPORT bool ReLoadModuleCode ()
 Rebuilds the module and tries to restore data. More...
 
DLLEXPORT void SetAsInvalid ()
 Sets the module as invalid to avoid usage. More...
 
DLLEXPORT void PrintFunctionsInModule ()
 
DLLEXPORT bool OnAddedToBridge (std::shared_ptr< ScriptArgumentsProviderBridge > bridge)
 Call when this module is added to a bridge. More...
 
- Public Member Functions inherited from Leviathan::ThreadSafeGeneric< MutexType >
DLLEXPORT ThreadSafeGeneric ()
 
DLLEXPORT ~ThreadSafeGeneric ()
 
FORCE_INLINE void VerifyLock (RecursiveLock &guard) const
 
FORCE_INLINE void VerifyLock (Lock &lockit) const
 

Static Public Member Functions

static DLLEXPORT int ScriptModuleIncludeCallback (const char *include, const char *from, CScriptBuilder *builder, void *userParam)
 
static DLLEXPORT std::string ResolvePathToScriptFile (const std::string &inputfilename, const std::string &relativepath, bool checkworkdirrelative=true)
 Finds a path to source file or returns an empty string. More...
 

Static Public Attributes

static const std::map< std::string, int > ListenerNameType
 

Additional Inherited Members

- Protected Attributes inherited from Leviathan::ThreadSafeGeneric< MutexType >
MutexType ObjectsLock
 

Detailed Description

Definition at line 87 of file ScriptModule.h.

Constructor & Destructor Documentation

◆ ScriptModule()

ScriptModule::ScriptModule ( asIScriptEngine *  engine,
const std::string &  name,
int  id,
const std::string &  source 
)

Definition at line 15 of file ScriptModule.cpp.

16  :
17  Name(name),
18  Source(source), ID(id), ScriptBuilder(new CScriptBuilder())
19 {
20  {
21  Lock lock(ModuleBuildingMutex);
22  ModuleName = std::string(source + "_;" + Convert::ToString<int>(LatestAssigned));
23  LatestAssigned++;
24  }
25 
26  // module will always be started //
27  ScriptBuilder->StartNewModule(engine, ModuleName.c_str());
28 
29  // setup include resolver //
30  ScriptBuilder->SetIncludeCallback(ScriptModuleIncludeCallback, this);
31 
32  // Apply the default mask //
33  ScriptBuilder->GetModule()->SetAccessMask(AccessMask);
34 
35  ListenerDataBuilt = false;
36 }
static DLLEXPORT int ScriptModuleIncludeCallback(const char *include, const char *from, CScriptBuilder *builder, void *userParam)
std::unique_lock< std::mutex > Lock
Definition: ThreadSafe.h:16

◆ ~ScriptModule()

ScriptModule::~ScriptModule ( )

Definition at line 38 of file ScriptModule.cpp.

38 {}

Member Function Documentation

◆ AddAccessRight()

DLLEXPORT void Leviathan::ScriptModule::AddAccessRight ( AccessFlags  newaccess)
inline

Adds flags to the AccessMask.

See also
SetAccessMask

Definition at line 106 of file ScriptModule.h.

107  {
108  AccessMask |= newaccess;
109  }

◆ AddScriptSegment() [1/2]

DLLEXPORT FORCE_INLINE bool Leviathan::ScriptModule::AddScriptSegment ( const std::string &  file,
int  line,
const std::string &  code 
)
inline

Adds a new script section.

Returns
True when the file is not included already (and it got added), false otherwise

Definition at line 184 of file ScriptModule.h.

186  {
187  return AddScriptSegment(std::make_shared<ScriptSourceFileData>(file, line, code));
188  }
DLLEXPORT FORCE_INLINE bool AddScriptSegment(const std::string &file, int line, const std::string &code)
Adds a new script section.
Definition: ScriptModule.h:184

◆ AddScriptSegment() [2/2]

DLLEXPORT bool Leviathan::ScriptModule::AddScriptSegment ( std::shared_ptr< ScriptSourceFileData data)

The actual implementation of AddScriptSegment.

Definition at line 416 of file ScriptModule.cpp.

418 {
419  GUARD_LOCK();
420  // Check is it already there //
421  for(size_t i = 0; i < ScriptSourceSegments.size(); i++) {
422 
423  if(ScriptSourceSegments[i]->SourceFile == data->SourceFile &&
424  (abs(ScriptSourceSegments[i]->StartLine - data->StartLine) <= 2)) {
425 
426  return false;
427  }
428  }
429 
430  ScriptSourceSegments.push_back(data);
431 
432  // Needs to be built next //
433  ScriptState = SCRIPTBUILDSTATE_READYTOBUILD;
434  return true;
435 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ AddScriptSegmentFromFile()

DLLEXPORT bool Leviathan::ScriptModule::AddScriptSegmentFromFile ( const std::string &  file)

Adds an entire file as a script segment.

Returns
True when the file is added, false if the file was already added

Definition at line 437 of file ScriptModule.cpp.

438 {
439  GUARD_LOCK();
440 
441  std::string expanded;
442 
443  try {
444  expanded = boost::filesystem::canonical(file).generic_string();
445  } catch(const boost::filesystem::filesystem_error&) {
446  // Doesn't exist //
447  return false;
448  }
449 
450  // Check is it already there //
451  for(size_t i = 0; i < ScriptSourceSegments.size(); i++) {
452 
453  if(ScriptSourceSegments[i]->SourceFile == file) {
454 
455  return false;
456  }
457  }
458 
459  // Load the source code from the file //
460  std::string scriptdata;
461  FileSystem::ReadFileEntirely(expanded, scriptdata);
462 
463  ScriptSourceSegments.push_back(
464  std::make_shared<ScriptSourceFileData>(expanded, 1, scriptdata));
465 
466  // Needs to be built next //
467  ScriptState = SCRIPTBUILDSTATE_READYTOBUILD;
468  return true;
469 }
static DLLEXPORT bool ReadFileEntirely(const std::string &file, std::string &resultreceiver)
Definition: FileSystem.cpp:543
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ DeleteThisModule()

DLLEXPORT void Leviathan::ScriptModule::DeleteThisModule ( )

Definition at line 188 of file ScriptModule.cpp.

189 {
190 
191  // Tell script interface to unload this //
193 }
static DLLEXPORT ScriptExecutor * Get()
DLLEXPORT void DeleteModule(ScriptModule *ptrtomatch)

◆ DoesListenersContainSpecificListener()

DLLEXPORT bool Leviathan::ScriptModule::DoesListenersContainSpecificListener ( const std::string &  listenername,
const std::string *  generictype = NULL 
)

Definition at line 131 of file ScriptModule.cpp.

133 {
134  GUARD_LOCK();
135  // find from the map //
136  auto itr = _GetIteratorOfListener(guard, listenername, generictype);
137 
138  if(itr != FoundListenerFunctions.end()) {
139 
140  // it exists //
141  return true;
142  }
143  // no matching listener //
144  return false;
145 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ GetID()

DLLEXPORT int Leviathan::ScriptModule::GetID ( )
inline

Definition at line 136 of file ScriptModule.h.

137  {
138  return ID;
139  }

◆ GetIncompleteSourceCode()

DLLEXPORT const std::string& Leviathan::ScriptModule::GetIncompleteSourceCode ( )
inline

Definition at line 146 of file ScriptModule.h.

147  {
148  return ObjectFileLoadedScriptCode;
149  }

◆ GetInfoString()

DLLEXPORT std::string Leviathan::ScriptModule::GetInfoString ( )

Definition at line 182 of file ScriptModule.cpp.

183 {
184 
185  return "ScriptModule(" + Convert::ToString(ID) + ") " + Name + ", from: " + Source;
186 }
static std::string ToString(const T &val)
Definition: Convert.h:72

◆ GetListeningFunctionName()

DLLEXPORT std::string Leviathan::ScriptModule::GetListeningFunctionName ( const std::string &  listenername,
const std::string *  generictype = NULL 
)

Definition at line 164 of file ScriptModule.cpp.

166 {
167  GUARD_LOCK();
168 
169  // Call search function and check if it found anything //
170  auto itr = _GetIteratorOfListener(guard, listenername, generictype);
171 
172 
173  if(itr != FoundListenerFunctions.end()) {
174  // Get name from pointer //
175  return std::string(itr->second->FuncPtr->GetName());
176  }
177 
178  // Nothing found //
179  return "";
180 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ GetListOfListeners()

DLLEXPORT void Leviathan::ScriptModule::GetListOfListeners ( std::vector< std::shared_ptr< ValidListenerData >> &  receiver)

Definition at line 147 of file ScriptModule.cpp.

149 {
150  GUARD_LOCK();
151  // build info if not built //
152  if(!ListenerDataBuilt)
153  _BuildListenerList(guard);
154  // reserve space to be more efficient //
155  receiver.reserve(FoundListenerFunctions.size());
156 
157 
158  for(auto iter = FoundListenerFunctions.begin(); iter != FoundListenerFunctions.end();
159  ++iter) {
160  receiver.push_back(iter->second);
161  }
162 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ GetModule() [1/2]

DLLEXPORT asIScriptModule * Leviathan::ScriptModule::GetModule ( Lock guard)

Builds the script if applicable.

Returns
The associated module or NULL if build fails

Definition at line 79 of file ScriptModule.cpp.

80 {
81 
82  // we need to check build state //
83  if(ScriptState == SCRIPTBUILDSTATE_READYTOBUILD) {
84 
85  _BuildTheModule(guard);
86 
87 #ifdef SCRIPTMODULE_LISTENFORFILECHANGES
88 
89  _StartMonitoringFiles(guard);
90 
91 #endif // SCRIPTMODULE_LISTENFORFILECHANGES
92 
93  if(ScriptState != SCRIPTBUILDSTATE_BUILT) {
94 
95  return NULL;
96  }
97 
98  } else if(ScriptState == SCRIPTBUILDSTATE_FAILED ||
99  ScriptState == SCRIPTBUILDSTATE_DISCARDED) {
100 
101  return NULL;
102  }
103 
104  // Return the saved pointer or fetch the pointer //
105  if(!ASModule) {
106 
107  // Get module from the engine //
108  ASModule = ScriptExecutor::Get()->GetASEngine()->GetModule(
109  ModuleName.c_str(), asGM_ONLY_IF_EXISTS);
110 
111  if(!ASModule) {
112 
113  // The module is invalid //
114  LOG_ERROR("ScriptModule: GetModule: module is no longer anywhere "
115  "to be found in the AS engine");
116 
117  ScriptState = SCRIPTBUILDSTATE_DISCARDED;
118  return NULL;
119  }
120  }
121 
122  return ASModule;
123 }
DLLEXPORT asIScriptEngine * GetASEngine()
#define LOG_ERROR(x)
Definition: Define.h:83
static DLLEXPORT ScriptExecutor * Get()

◆ GetModule() [2/2]

DLLEXPORT asIScriptModule* Leviathan::ScriptModule::GetModule ( )
inline

Definition at line 115 of file ScriptModule.h.

116  {
117  GUARD_LOCK();
118  return GetModule(guard);
119  }
#define GUARD_LOCK()
Definition: ThreadSafe.h:97
DLLEXPORT asIScriptModule * GetModule()
Definition: ScriptModule.h:115

◆ GetModuleName()

DLLEXPORT const std::string & Leviathan::ScriptModule::GetModuleName ( ) const

Gets the name of the internal AngelScript module.

Definition at line 471 of file ScriptModule.cpp.

472 {
473  return ModuleName;
474 }

◆ GetName()

DLLEXPORT std::string Leviathan::ScriptModule::GetName ( )
inline

Definition at line 124 of file ScriptModule.h.

125  {
126  return Name;
127  }

◆ GetScriptInstance()

DLLEXPORT std::shared_ptr< ScriptScript > Leviathan::ScriptModule::GetScriptInstance ( )

Definition at line 125 of file ScriptModule.cpp.

126 {
127 
128  return std::make_shared<ScriptScript>(ID, ScriptExecutor::Get()->GetModule(ID));
129 }
static DLLEXPORT ScriptExecutor * Get()
DLLEXPORT std::weak_ptr< ScriptModule > GetModule(const int &ID)

◆ GetScriptSegment()

DLLEXPORT std::shared_ptr< ScriptSourceFileData > Leviathan::ScriptModule::GetScriptSegment ( size_t  index) const

Gets the data associated with a code segment.

Parameters
indexThe index of the segment in the vector, use GetScriptSegmentCount to get max index
Returns
The segments data or NULL

Definition at line 407 of file ScriptModule.cpp.

409 {
410  if(index >= ScriptSourceSegments.size())
411  return NULL;
412 
413  return ScriptSourceSegments[index];
414 }

◆ GetScriptSegmentCount()

DLLEXPORT size_t Leviathan::ScriptModule::GetScriptSegmentCount ( ) const

Gets the number of code segments.

See also
GetScriptSegment

Definition at line 402 of file ScriptModule.cpp.

403 {
404  return ScriptSourceSegments.size();
405 }

◆ GetSource()

DLLEXPORT const std::string& Leviathan::ScriptModule::GetSource ( ) const
inline

Definition at line 141 of file ScriptModule.h.

142  {
143  return Source;
144  }

◆ OnAddedToBridge()

DLLEXPORT bool Leviathan::ScriptModule::OnAddedToBridge ( std::shared_ptr< ScriptArgumentsProviderBridge bridge)

Call when this module is added to a bridge.

Returns
True when this is not in a bridge and it is added, false if this is removed from the bridge

Definition at line 770 of file ScriptModule.cpp.

772 {
773  LEVIATHAN_ASSERT(this == bridge->GetModule(), "OnAddedToBridge it's not ours!");
774 
775  if(ArgsBridge) {
776 
777  return false;
778  }
779 
780  ArgsBridge = bridge;
781  return true;
782 }

◆ PrintFunctionsInModule()

DLLEXPORT void Leviathan::ScriptModule::PrintFunctionsInModule ( )

Definition at line 348 of file ScriptModule.cpp.

349 {
350  GUARD_LOCK();
351 
352  // list consoles' global variables //
353  Logger::Get()->Info(Name + " instance functions: ");
354 
355  // List the user functions in the module
356  asIScriptModule* mod = GetModule(guard);
357 
358  const asUINT FuncCount = mod->GetFunctionCount();
359 
360  for(asUINT n = 0; n < FuncCount; n++) {
361  // get function //
362  asIScriptFunction* func = mod->GetFunctionByIndex(n);
363  // print the function //
364  Logger::Get()->Write(
365  std::string("> ") + func->GetName() + "(" + func->GetDeclaration() + ")");
366  }
367 
368  Logger::Get()->Write("[END]");
369 }
DLLEXPORT void Write(const std::string &data) override
Definition: Logger.cpp:113
DLLEXPORT void Info(const std::string &data) override
Definition: Logger.cpp:164
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
#define GUARD_LOCK()
Definition: ThreadSafe.h:97
DLLEXPORT asIScriptModule * GetModule()
Definition: ScriptModule.h:115

◆ Release()

DLLEXPORT void Leviathan::ScriptModule::Release ( )

Releases the internal resources.

Definition at line 40 of file ScriptModule.cpp.

41 {
42  GUARD_LOCK();
43 
44  // Leave from the bridge //
45  if(ArgsBridge)
46  ArgsBridge->LeaveModule();
47 
48 
49 #ifdef SCRIPTMODULE_LISTENFORFILECHANGES
50 
51  _StopFileMonitoring(guard);
52 
53 #endif // SCRIPTMODULE_LISTENFORFILECHANGES
54 
55  // We'll need to destroy the module from the engine //
56  ASModule = NULL;
57  ScriptExecutor::Get()->GetASEngine()->DiscardModule(ModuleName.c_str());
58 
59  // And then delete the builder //
60  SAFE_DELETE(ScriptBuilder);
61  ListenerDataBuilt = false;
62 }
DLLEXPORT asIScriptEngine * GetASEngine()
static DLLEXPORT ScriptExecutor * Get()
#define SAFE_DELETE(x)
Definition: Define.h:116
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ ReLoadModuleCode()

DLLEXPORT bool Leviathan::ScriptModule::ReLoadModuleCode ( )

Rebuilds the module and tries to restore data.

Not all data can be restored (things changing types, application owned handles etc...)

Definition at line 483 of file ScriptModule.cpp.

484 {
485  GUARD_LOCK();
486 
487  // The module must be still valid //
488  if(ScriptState == SCRIPTBUILDSTATE_DISCARDED ||
489  (!GetModule() && ScriptState != SCRIPTBUILDSTATE_FAILED))
490  return false;
491 
492 
493  Logger::Get()->Info("Reloading " + GetInfoString());
494 
495  if(ArgsBridge) {
496 
497  // Do a OnRelease event call //
498  const std::string& listenername =
500 
501  // check does the script contain right listeners //
502  if(DoesListenersContainSpecificListener(listenername)) {
503 
504  // Get the parameters //
505  auto sargs = ArgsBridge->GetProvider()->GetParametersForRelease();
506  // sargs.Parameters need to be somehow translated to the new style
507  DEBUG_BREAK;
508  sargs->SetEntrypoint(GetListeningFunctionName(listenername));
509 
510  // Run the script //
511  auto result = ScriptExecutor::Get()->RunScript<void>(shared_from_this(), *sargs);
512 
513  if(result.Result != SCRIPT_RUN_RESULT::Success) {
514 
515  LOG_ERROR("ScriptModule: failed to run auto release, skipping reload");
516  return false;
517  } else {
518 
519  Logger::Get()->Info("ScriptModule: ran auto release");
520  }
521  }
522  }
523 
524 
525  // Store the old values //
526  // CSerializer backup;
527  // backup.Store(ASModule);
528 
529  // Discard the old module //
530  ASModule = NULL;
531  if(GetModule())
532  ScriptExecutor::Get()->GetASEngine()->DiscardModule(ModuleName.c_str());
533 
534  // The builder must be created again //
535  SAFE_DELETE(ScriptBuilder);
536 
537  // Setup the new builder //
538  ScriptBuilder = new CScriptBuilder();
539 
540  asIScriptEngine* engine = ScriptExecutor::Get()->GetASEngine();
541 
542  // Add 'R' to the module name to mark reload //
543  ModuleName += "R";
544 
545  ScriptBuilder->StartNewModule(engine, ModuleName.c_str());
546  ScriptBuilder->SetIncludeCallback(ScriptModuleIncludeCallback, this);
547  ListenerDataBuilt = false;
548 
549  // Build the module //
550  _BuildTheModule(guard);
551 
552  if(ScriptState != SCRIPTBUILDSTATE_BUILT || !GetModule()) {
553 
554  // Failed to build //
555  return false;
556  }
557 
558  // Restore the data //
559  // backup.Restore(GetModule());
560 
561  // Logger::Get()->Info("Successfully restored "+GetInfoStd::String());
562 
563  if(ArgsBridge) {
564 
565  // Do a OnRelease event call //
566  const std::string& listenername =
568 
569  // check does the script contain right listeners //
570  if(DoesListenersContainSpecificListener(listenername)) {
571 
572  // Get the parameters //
573  auto sargs = ArgsBridge->GetProvider()->GetParametersForInit();
574  // sargs.Parameters need to be somehow translated to the new style
575  DEBUG_BREAK;
576  sargs->SetEntrypoint(GetListeningFunctionName(listenername));
577 
578 
579  // Run the script //
580  auto result = ScriptExecutor::Get()->RunScript<void>(shared_from_this(), *sargs);
581 
582  if(result.Result != SCRIPT_RUN_RESULT::Success) {
583 
584  LOG_ERROR("ScriptModule: failed to run auto init after restore");
585  // We don't want to signal failure as we have already overwritten our old stuff
586  } else {
587 
588  Logger::Get()->Info("ScriptModule: ran auto init after restore");
589  }
590  }
591  }
592 
593  // Succeeded //
594  return true;
595 }
ScriptRunResult< ReturnT > RunScript(const std::shared_ptr< ScriptModule > &module, ScriptRunningSetup &parameters, Args &&... args)
Runs a function in a script.
DLLEXPORT asIScriptEngine * GetASEngine()
DLLEXPORT void Info(const std::string &data) override
Definition: Logger.cpp:164
#define LOG_ERROR(x)
Definition: Define.h:83
static DLLEXPORT std::string GetListenerNameFromType(EVENT_TYPE type)
static DLLEXPORT ScriptExecutor * Get()
static DLLEXPORT int ScriptModuleIncludeCallback(const char *include, const char *from, CScriptBuilder *builder, void *userParam)
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
DLLEXPORT std::string GetListeningFunctionName(const std::string &listenername, const std::string *generictype=NULL)
DLLEXPORT bool DoesListenersContainSpecificListener(const std::string &listenername, const std::string *generictype=NULL)
#define SAFE_DELETE(x)
Definition: Define.h:116
#define GUARD_LOCK()
Definition: ThreadSafe.h:97
DLLEXPORT asIScriptModule * GetModule()
Definition: ScriptModule.h:115
DLLEXPORT std::string GetInfoString()

◆ ResolvePathToScriptFile()

DLLEXPORT std::string ScriptModule::ResolvePathToScriptFile ( const std::string &  inputfilename,
const std::string &  relativepath,
bool  checkworkdirrelative = true 
)
static

Finds a path to source file or returns an empty string.

Definition at line 784 of file ScriptModule.cpp.

786 {
787  // The canonical calls here are probably not needed as the as
788  // script builder makes all paths absolute
789 
790  // Check first relative, absolute, and then search //
791  const auto asRelative = boost::filesystem::path(relativepath) / inputfilename;
792  if(boost::filesystem::is_regular_file(asRelative)) {
793  return boost::filesystem::canonical(asRelative).generic_string();
794 
795  } else if(checkworkdirrelative && boost::filesystem::is_regular_file(inputfilename)) {
796 
797  return boost::filesystem::canonical(inputfilename).generic_string();
798 
799  } else {
800 
801  // This returns an empty string for us //
802  std::string searched = FileSystem::Get()->SearchForFile(FILEGROUP_SCRIPT,
803  StringOperations::RemoveExtension<std::string>(inputfilename),
804  StringOperations::GetExtension<std::string>(inputfilename), false);
805 
806  if(searched.empty())
807  return searched;
808 
809  return boost::filesystem::canonical(searched).generic_string();
810  }
811 }
static DLLEXPORT FileSystem * Get()
Definition: FileSystem.cpp:78
DLLEXPORT std::string SearchForFile(FILEGROUP which, const std::string &name, const std::string &extensions, bool searchall=true)
Searches for a file.
Definition: FileSystem.cpp:671

◆ ScriptModuleIncludeCallback()

DLLEXPORT int Leviathan::ScriptModule::ScriptModuleIncludeCallback ( const char *  include,
const char *  from,
CScriptBuilder *  builder,
void *  userParam 
)
static

Definition at line 371 of file ScriptModule.cpp.

373 {
374  std::string file(include);
375  std::string infile(from);
376 
377  ScriptModule* module = reinterpret_cast<ScriptModule*>(userParam);
378  // The module has to be locked during this call
379 
380  // Resolve it to an usable path //
381  const auto resolved = ResolvePathToScriptFile(file, infile);
382 
383  if(resolved.empty() || !boost::filesystem::exists(resolved)) {
384 
385  Logger::Get()->Error("ScriptModule: IncludeCallback: couldn't resolve include "
386  "(even with full search), file: " +
387  file + " included in: " + infile + ", while compiling " +
388  module->GetInfoString());
389 
390  // Including failed
391  return -1;
392  }
393 
394 #ifdef SCRIPTMODULE_LISTENFORFILECHANGES
395 
396  module->_AddFileToMonitorIfNotAlready(resolved);
397 #endif // SCRIPTMODULE_LISTENFORFILECHANGES
398 
399  return builder->AddSectionFromFile(resolved.c_str());
400 }
static DLLEXPORT std::string ResolvePathToScriptFile(const std::string &inputfilename, const std::string &relativepath, bool checkworkdirrelative=true)
Finds a path to source file or returns an empty string.
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
DLLEXPORT void Error(const std::string &data) override
Definition: Logger.cpp:177
DLLEXPORT std::string GetInfoString()

◆ SetAccessMask()

DLLEXPORT void Leviathan::ScriptModule::SetAccessMask ( AccessFlags  access)
inline

Sets the access mask to be used for this script.

This only takes effect before building the module

Definition at line 99 of file ScriptModule.h.

100  {
101  AccessMask = access;
102  }

◆ SetAsInvalid()

DLLEXPORT void Leviathan::ScriptModule::SetAsInvalid ( )

Sets the module as invalid to avoid usage.

Definition at line 476 of file ScriptModule.cpp.

477 {
478  GUARD_LOCK();
479 
480  ScriptState = SCRIPTBUILDSTATE_DISCARDED;
481 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ SetBuildState()

DLLEXPORT void Leviathan::ScriptModule::SetBuildState ( const SCRIPTBUILDSTATE state)
inline

Definition at line 165 of file ScriptModule.h.

166  {
167  ScriptState = state;
168  }

Member Data Documentation

◆ ListenerNameType


The documentation for this class was generated from the following files: