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

- Public Types inherited from Leviathan::ThreadSafeGeneric< MutexType >
using LockT = typename LockTypeResolver< MutexType >::LType
 
- Protected Attributes inherited from Leviathan::ThreadSafeGeneric< MutexType >
MutexType ObjectsLock
 

Detailed Description

Definition at line 62 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 16 of file ScriptModule.cpp.

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

◆ ~ScriptModule()

ScriptModule::~ScriptModule ( )

Definition at line 39 of file ScriptModule.cpp.

39 {}

Member Function Documentation

◆ AddAccessRight()

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

Adds flags to the AccessMask.

See also
SetAccessMask

Definition at line 81 of file ScriptModule.h.

82  {
83  AccessMask |= newaccess;
84  }

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

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

◆ AddScriptSegment() [2/2]

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

The actual implementation of AddScriptSegment.

Definition at line 417 of file ScriptModule.cpp.

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

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

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

◆ DeleteThisModule()

DLLEXPORT void Leviathan::ScriptModule::DeleteThisModule ( )

Definition at line 189 of file ScriptModule.cpp.

190 {
191 
192  // Tell script interface to unload this //
194 }
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 132 of file ScriptModule.cpp.

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

◆ GetID()

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

Definition at line 111 of file ScriptModule.h.

112  {
113  return ID;
114  }

◆ GetIncompleteSourceCode()

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

Definition at line 121 of file ScriptModule.h.

122  {
123  return ObjectFileLoadedScriptCode;
124  }

◆ GetInfoString()

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

Definition at line 183 of file ScriptModule.cpp.

184 {
185 
186  return "ScriptModule(" + Convert::ToString(ID) + ") " + Name + ", from: " + Source;
187 }
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 165 of file ScriptModule.cpp.

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

◆ GetListOfListeners()

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

Definition at line 148 of file ScriptModule.cpp.

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

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

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

◆ GetModule() [2/2]

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

Definition at line 90 of file ScriptModule.h.

91  {
92  GUARD_LOCK();
93  return GetModule(guard);
94  }
#define GUARD_LOCK()
Definition: ThreadSafe.h:111
DLLEXPORT asIScriptModule * GetModule()
Definition: ScriptModule.h:90

◆ GetModuleName()

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

Gets the name of the internal AngelScript module.

Definition at line 472 of file ScriptModule.cpp.

473 {
474  return ModuleName;
475 }

◆ GetName()

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

Definition at line 99 of file ScriptModule.h.

100  {
101  return Name;
102  }

◆ GetScriptInstance()

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

Definition at line 126 of file ScriptModule.cpp.

127 {
128 
129  return std::make_shared<ScriptScript>(ID, ScriptExecutor::Get()->GetModule(ID));
130 }
static DLLEXPORT ScriptExecutor * Get()
DLLEXPORT asIScriptModule * GetModule()
Definition: ScriptModule.h:90

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

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

◆ GetScriptSegmentCount()

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

Gets the number of code segments.

See also
GetScriptSegment

Definition at line 403 of file ScriptModule.cpp.

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

◆ GetSource()

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

Definition at line 116 of file ScriptModule.h.

117  {
118  return Source;
119  }

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

773 {
774  LEVIATHAN_ASSERT(this == bridge->GetModule(), "OnAddedToBridge it's not ours!");
775 
776  if(ArgsBridge) {
777 
778  return false;
779  }
780 
781  ArgsBridge = bridge;
782  return true;
783 }
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:104

◆ PrintFunctionsInModule()

DLLEXPORT void Leviathan::ScriptModule::PrintFunctionsInModule ( )

Definition at line 349 of file ScriptModule.cpp.

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

◆ Release()

DLLEXPORT void Leviathan::ScriptModule::Release ( )

Releases the internal resources.

Definition at line 41 of file ScriptModule.cpp.

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

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

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

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

◆ ScriptModuleIncludeCallback()

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

Definition at line 372 of file ScriptModule.cpp.

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

75  {
76  AccessMask = access;
77  }

◆ SetAsInvalid()

DLLEXPORT void Leviathan::ScriptModule::SetAsInvalid ( )

Sets the module as invalid to avoid usage.

Definition at line 477 of file ScriptModule.cpp.

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

◆ SetBuildState()

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

Definition at line 140 of file ScriptModule.h.

141  {
142  ScriptState = state;
143  }

Member Data Documentation

◆ ListenerNameType


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