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:15

◆ ~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 185 of file ScriptModule.h.

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

◆ AddScriptSegment() [2/2]

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

The actual implementation of AddScriptSegment.

Definition at line 412 of file ScriptModule.cpp.

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

◆ 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 433 of file ScriptModule.cpp.

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

◆ 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:91

◆ GetID()

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

Definition at line 137 of file ScriptModule.h.

138  {
139  return ID;
140  }

◆ GetIncompleteSourceCode()

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

Definition at line 147 of file ScriptModule.h.

148  {
149  return ObjectFileLoadedScriptCode;
150  }

◆ 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:91

◆ 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:91

◆ 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 
118  GUARD_LOCK();
119  return GetModule(guard);
120  }
#define GUARD_LOCK()
Definition: ThreadSafe.h:91
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 467 of file ScriptModule.cpp.

468 {
469  return ModuleName;
470 }

◆ GetName()

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

Definition at line 125 of file ScriptModule.h.

126  {
127  return Name;
128  }

◆ 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 403 of file ScriptModule.cpp.

405 {
406  if(index >= ScriptSourceSegments.size())
407  return NULL;
408 
409  return ScriptSourceSegments[index];
410 }

◆ GetScriptSegmentCount()

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

Gets the number of code segments.

See also
GetScriptSegment

Definition at line 398 of file ScriptModule.cpp.

399 {
400  return ScriptSourceSegments.size();
401 }

◆ GetSource()

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

Definition at line 142 of file ScriptModule.h.

143  {
144  return Source;
145  }

◆ 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 766 of file ScriptModule.cpp.

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

◆ PrintFunctionsInModule()

DLLEXPORT void Leviathan::ScriptModule::PrintFunctionsInModule ( )

Definition at line 344 of file ScriptModule.cpp.

345 {
346 
347  GUARD_LOCK();
348  // list consoles' global variables //
349  Logger::Get()->Info(Name + " instance functions: ");
350 
351  // List the user functions in the module
352  asIScriptModule* mod = GetModule();
353 
354  const asUINT FuncCount = mod->GetFunctionCount();
355 
356  for(asUINT n = 0; n < FuncCount; n++) {
357  // get function //
358  asIScriptFunction* func = mod->GetFunctionByIndex(n);
359  // print the function //
360  Logger::Get()->Write(
361  std::string("> ") + func->GetName() + "(" + func->GetDeclaration() + ")");
362  }
363 
364  Logger::Get()->Write("[END]");
365 }
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:91
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:91

◆ 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 479 of file ScriptModule.cpp.

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

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

◆ ScriptModuleIncludeCallback()

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

Definition at line 367 of file ScriptModule.cpp.

369 {
370  std::string file(include);
371  std::string infile(from);
372 
373  ScriptModule* module = reinterpret_cast<ScriptModule*>(userParam);
374  // The module has to be locked during this call
375 
376  // Resolve it to an usable path //
377  const auto resolved = ResolvePathToScriptFile(file, infile);
378 
379  if(resolved.empty() || !boost::filesystem::exists(resolved)) {
380 
381  Logger::Get()->Error("ScriptModule: IncludeCallback: couldn't resolve include "
382  "(even with full search), file: " +
383  file + " included in: " + infile + ", while compiling " +
384  module->GetInfoString());
385 
386  // Including failed
387  return -1;
388  }
389 
390 #ifdef SCRIPTMODULE_LISTENFORFILECHANGES
391 
392  module->_AddFileToMonitorIfNotAlready(resolved);
393 #endif // SCRIPTMODULE_LISTENFORFILECHANGES
394 
395  return builder->AddSectionFromFile(resolved.c_str());
396 }
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 472 of file ScriptModule.cpp.

473 {
474  GUARD_LOCK();
475 
476  ScriptState = SCRIPTBUILDSTATE_DISCARDED;
477 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:91

◆ SetBuildState()

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

Definition at line 166 of file ScriptModule.h.

167  {
168  ScriptState = state;
169  }

Member Data Documentation

◆ ListenerNameType


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