code:
var doc_addon_application =
[
    [ "Script builder", "doc_addon_build.html", [
      [ "Public C++ interface", "doc_addon_build.html#doc_addon_build_1", [
        [ "The include callback signature", "doc_addon_build.html#doc_addon_build_1_1", null ],
        [ "The pragma callback signature", "doc_addon_build.html#doc_addon_build_1_2", null ]
      ] ],
      [ "Include directives", "doc_addon_build.html#doc_addon_build_2", null ],
      [ "Conditional programming", "doc_addon_build.html#doc_addon_build_condition", null ],
      [ "Metadata in scripts", "doc_addon_build.html#doc_addon_build_metadata", null ]
    ] ],
    [ "Context manager", "doc_addon_ctxmgr.html", [
      [ "Public C++ interface", "doc_addon_ctxmgr.html#doc_addon_ctxmgr_1", null ],
      [ "Public script interface", "doc_addon_ctxmgr.html#doc_addon_ctxmgr_2", null ]
    ] ],
    [ "Debugger", "doc_addon_debugger.html", [
      [ "Public C++ interface", "doc_addon_debugger.html#doc_addon_debugger_1", null ],
      [ "Example usage", "doc_addon_debugger.html#doc_addon_debugger_2", null ]
    ] ],
    [ "Serializer", "doc_addon_serializer.html", [
      [ "Public C++ interface", "doc_addon_serializer.html#doc_addon_serializer_1", null ],
      [ "Example usage", "doc_addon_serializer.html#doc_addon_serializer_2", null ]
    ] ],
    [ "Helper functions", "doc_addon_helpers.html", [
      [ "Public C++ interface", "doc_addon_helpers.html#doc_addon_helpers_1", null ],
      [ "Example", "doc_addon_helpers.html#doc_addon_helpers_2", null ]
    ] ],
    [ "Automatic wrapper functions", "doc_addon_autowrap.html", [
      [ "Example usage", "doc_addon_autowrap.html#doc_addon_autowrap_1", null ],
      [ "Adding support for more parameters", "doc_addon_autowrap.html#doc_addon_autowrap_2", null ]
    ] ]
];


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: array template object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

array template object

Path: /sdk/add_on/scriptarray/

The array type is a template object that allow the scripts to declare arrays of any type. Since it is a generic class it is not the most performatic due to the need to determine characteristics at runtime. For that reason it is recommended that the application registers a template specialization for the array types that are most commonly used.

The type is registered with RegisterScriptArray(asIScriptEngine *engine, bool defaultArrayType). The second parameter should be set to true if you wish to allow the syntax form type[] to declare arrays.

Compile the add-on with the pre-processor define AS_USE_STLNAMES=1 to register the methods with the same names as used by C++ STL where the methods have the same significance. Not all methods from STL is implemented in the add-on, but many of the most frequent once are so a port from script to C++ and vice versa might be easier if STL names are used.

Compile the add-on with the pre-processor define AS_USE_ACCESSORS=1 to register length as a virtual property instead of the method length().

Compile the add-on with the pre-processor define AS_NO_IMPL_OPS_WITH_STRING_AND_PRIMITIVE=1 to disable the implicit operations with primitives that automatically formats the primitive values to strings.

Public C++ interface

class CScriptArray

{

public:

  // Set the memory functions that should be used by all CScriptArrays

  static void SetMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc);

  // Factory functions

  static CScriptArray *Create(asITypeInfo *arrayType);

  static CScriptArray *Create(asITypeInfo *arrayType, asUINT length);

  static CScriptArray *Create(asITypeInfo *arrayType, asUINT length, void *defaultValue);

  static CScriptArray *Create(asITypeInfo *arrayType, void *listBuffer);

  // Memory management

  void AddRef() const;

  void Release() const;

  // Type information

  asITypeInfo   *GetArrayObjectType() const;

  int            GetArrayTypeId() const;

  int            GetElementTypeId() const;

  // Get the current size

  asUINT GetSize() const;

  // Returns true if the array is empty

  bool IsEmpty() const;

  // Pre-allocates memory for elements

  void Reserve(asUINT numElements);

  // Resize the array

  void Resize(asUINT numElements);

  // Get a pointer to an element. Returns 0 if out of bounds

  void       *At(asUINT index);

  const void *At(asUINT index) const;

  // Set value of an element.

  // The value arg should be a pointer to the value that will be copied to the element.

  // Remember, if the array holds handles the value parameter should be the

  // address of the handle. The refCount of the object will also be incremented

  void  SetValue(asUINT index, void *value);

  // Copy the contents of one array to another (only if the types are the same)

  CScriptArray &operator=(const CScriptArray&);

  // Compare two arrays

  bool operator==(const CScriptArray &) const;

  // Array manipulation

  void InsertAt(asUINT index, void *value);

  void RemoveAt(asUINT index);

  void InsertLast(void *value);

  void RemoveLast();

  void SortAsc();

  void SortAsc(asUINT startAt, asUINT count);

  void SortDesc();

  void SortDesc(asUINT startAt, asUINT count);

  void Sort(asUINT startAt, asUINT count, bool asc);

  void Sort(asIScriptFunction *less, asUINT startAt, asUINT count);

  void Reverse();

  int  Find(void *value) const;

  int  Find(asUINT startAt, void *value) const;

  int  FindByRef(void *ref) const;

  int  FindByRef(asUINT startAt, void *ref) const;

  // Returns the address of the inner buffer for direct manipulation

  void *GetBuffer();

};

asALLOCFUNC_t

void *(* asALLOCFUNC_t)(size_t)

The function signature for the custom memory allocation function.

Definition: angelscript.h:645

asUINT

unsigned int asUINT

32 bit unsigned integer

Definition: angelscript.h:610

asFREEFUNC_t

void(* asFREEFUNC_t)(void *)

The function signature for the custom memory deallocation function.

Definition: angelscript.h:647

asIScriptFunction

The interface for a script function description.

Definition: angelscript.h:4000

asITypeInfo

The interface for describing types This interface is used to describe the types in the script engine.

Definition: angelscript.h:3704

Public script interface

See also

Arrays in the script language

C++ example

This function shows how a script array can be instantiated from the application and then passed to the script.

// Registered with AngelScript as 'array<string> @CreateArrayOfString()'

CScriptArray *CreateArrayOfStrings()

{

  // If called from the script, there will always be an active

  // context, which can be used to obtain a pointer to the engine.

  asIScriptContext *ctx = asGetActiveContext();

  if( ctx )

  {

    asIScriptEngine* engine = ctx->GetEngine();

    // The script array needs to know its type to properly handle the elements.

    // Note that the object type should be cached to avoid performance issues

    // if the function is called frequently.

    asITypeInfo* t = engine->GetTypeInfoByDecl("array<string>");

    // Create an array with the initial size of 3 elements

    CScriptArray* arr = CScriptArray::Create(t, 3);

    for( asUINT i = 0; i < arr->GetSize(); i++ )

    {

      // Set the value of each element

      string val("test");

      arr->SetValue(i, &val);

    }

    // The ref count for the returned handle was already set in the array's constructor

    return arr;

  }

  return 0;

}

asIScriptContext

The interface to the virtual machine.

Definition: angelscript.h:2735

asIScriptContext::GetEngine

virtual asIScriptEngine * GetEngine() const =0

Returns a pointer to the engine.

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

asIScriptEngine::GetTypeInfoByDecl

virtual asITypeInfo * GetTypeInfoByDecl(const char *decl) const =0

Returns a type by declaration.

asGetActiveContext

AS_API asIScriptContext * asGetActiveContext()

Returns the currently active context.

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6

repo_name: Antidote/openrpgeditor

license: mit


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Automatic wrapper functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Automatic wrapper functions

Path: /sdk/add_on/autowrapper/aswrappedcall.h

This header file declares some macros and template functions that will let the application developer automatically generate wrapper functions using the generic calling convention with a simple call to a preprocessor macro. This is useful for those platforms where the native calling conventions are not yet supported.

The macros are defined as:

// Wrap a global function with implicit or explicit signature

#define WRAP_FN(name)

#define WRAP_FN_PR(name, Parameters, ReturnType)

// Wrap a class method with implicit or explicit signature

#define WRAP_MFN(ClassType, name)

#define WRAP_MFN_PR(ClassType, name, Parameters, ReturnType)

// Wrap a global function that will emulate a class method and receives the 'this' pointer as the first argument

#define WRAP_OBJ_FIRST(name)

#define WRAP_OBJ_FIRST_PR(name, Parameters, ReturnType)

// Wrap a global function that will emulate a class method and receives the 'this' pointer as the last argument

#define WRAP_OBJ_LAST(name)

#define WRAP_OBJ_LAST_PR(name, Parameters, ReturnType)

// Wrap a constructor with an explicit signature

#define WRAP_CON(ClassType, Parameters)

// Wrap a destructor

#define WRAP_DES(ClassType)

As you can see they are very similar to the asFUNCTION and asMETHOD macros, and are used the same way.

Unfortunately the template functions needed to perform this generation are quite complex and older compilers may not be able to handle them. One such example is Microsoft Visual C++ 6, though luckily it has no need for them as AngelScript already supports native calling conventions for it.

Example usage

#include "aswrappedcall.h"

// The application function that we want to register

void DoSomething(std::string param1, int param2);

// Registering the wrapper with AngelScript

void RegisterWrapper(asIScriptEngine *engine)

{

  int r;

  // The WRAP_FN macro automatically implements and returns the function pointer of the generic wrapper

  // function. Observe, that the calling convention should be set as asCALL_GENERIC in this case.

  r = engine->RegisterGlobalFunction("void DoSomething(string, int)", WRAP_FN(DoSomething), asCALL_GENERIC); assert( r >= 0 );

}

asCALL_GENERIC

@ asCALL_GENERIC

A function using the generic calling convention.

Definition: angelscript.h:242

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

asIScriptEngine::RegisterGlobalFunction

virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary=0)=0

Registers a global function.

Adding support for more parameters

The aswrappedcall.h header file is by default prepared to support functions with up to 4 arguments. If you have a need for more arguments then you can use the generator that you find in the sub-directory to prepare a new header file.

Open the generateheader.cpp in an editor and set the max_args variable to the number of arguments you need and then compile and run the code. It will print the new header file to the standard output so you just need to direct this to a file.

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Script builder</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Script builder

Path: /sdk/add_on/scriptbuilder/

This class is a helper class for loading and building scripts, with a basic pre-processor that supports conditional compilation, include directives, pragma directives, and metadata declarations.

By default the script builder resolves include directives by loading the included file from the relative directory of the file it is included from. If you want to do this in another way, then you should implement the include callback which will let you process the include directive in a custom way, e.g. to load the included file from memory, or to support multiple search paths. The include callback should call the AddSectionFromFile or AddSectionFromMemory to include the section in the current build.

If the application should to support pragma directives, it must register the pragma callback to process the text provided for the pragma directive. Without the callback the script builder will give an error when encountering a pragma directive.

The script builder will also remove any lines that start with #! as comments. This is done to support shebang interpreter directives often used on Linux and UNIX based operative systems.

If you do not want process metadata then you can compile the add-on with the define AS_PROCESS_METADATA 0, which will exclude the code for processing this. This define can be made in the project settings or directly in the header.

Public C++ interface

class CScriptBuilder

{

public:

  // Start a new module

  int StartNewModule(asIScriptEngine *engine, const char *moduleName);

  // Load a script section from a file on disk

  // Returns  1 if the file was included

  //          0 if the file had already been included before

  //         <0 on error

  int AddSectionFromFile(const char *filename);

  // Load a script section from memory

  // Returns  1 if the section was included

  //          0 if a section with the same name had already been included before

  //         <0 on error

  int AddSectionFromMemory(const char *sectionName,

                           const char *scriptCode,

                           unsigned int scriptLength = 0,

                           int lineOffset = 0);

  // Build the added script sections

  int BuildModule();

  // Returns the script engine

  asIScriptEngine *GetEngine();

  // Returns the current module

  asIScriptModule *GetModule();

  // Register the callback for resolving include directive

  void SetIncludeCallback(INCLUDECALLBACK_t callback, void *userParam);

  // Register the callback for resolving pragma directive

  void SetPragmaCallback(PRAGMACALLBACK_t callback, void *userParam);

  // Add a pre-processor define for conditional compilation

  void DefineWord(const char *word);

  // Enumerate included script sections

  unsigned int GetSectionCount() const;

  string       GetSectionName(unsigned int idx) const;

  // Get metadata declared for classes, interfaces, and enums

  // Each metadata block, i.e. [...], is returned as a separate string

  std::vector<std::string> GetMetadataStringForType(int typeId);

  // Get metadata declared for functions

  // Each metadata block, i.e. [...], is returned as a separate string

  std::vector<std::string> GetMetadataStringForFunc(asIScriptFunction *func);

  // Get metadata declared for global variables

  // Each metadata block, i.e. [...], is returned as a separate string

  std::vector<std::string> GetMetadataStringForVar(int varIdx);

  // Get metadata declared for a class method

  // Each metadata block, i.e. [...], is returned as a separate string

  // Use the asIScriptFunction for the virtual method for lookup

  std::vector<std::string> GetMetadataStringForTypeMethod(int typeId, asIScriptFunction *method);

  // Get metadata declared for a class property

  // Each metadata block, i.e. [...], is returned as a separate string

  std::vector<std::string> GetMetadataStringForTypeProperty(int typeId, int varIdx);

};

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

asIScriptFunction

The interface for a script function description.

Definition: angelscript.h:4000

asIScriptModule

The interface to the script modules.

Definition: angelscript.h:2232

The include callback signature

// This callback will be called for each #include directive encountered by the

// builder. The callback should call the AddSectionFromFile or AddSectionFromMemory

// to add the included section to the script. If the include cannot be resolved

// then the function should return a negative value to abort the compilation.

typedef int (*INCLUDECALLBACK_t)(const char *include, const char *from, CScriptBuilder *builder, void *userParam);

The pragma callback signature

// This callback will be called for each #pragma directive encountered by the builder.

// The application can interpret the pragmaText and decide what do to based on that.

// If the callback returns a negative value the builder will report an error and abort the compilation.

typedef int(*PRAGMACALLBACK_t)(const std::string &pragmaText, CScriptBuilder &builder, void *userParam);

Include directives

Example script with include directive:

  #include "commonfuncs.as"

  void main()
  {
    // Call a function from the included file
    CommonFunc();
  }

Conditional programming

The builder supports conditional programming through the #if/#endif preprocessor directives. The application may define a word with a call to DefineWord(), then the scripts may check for this definition in the code in order to include/exclude parts of the code.

This is especially useful when scripts are shared between different binaries, for example, in a client/server application.

Example script with conditional compilation:

  class CObject
  {
    void Process()
    {
  #if SERVER
      // Do some server specific processing
  #endif

  #if CLIENT
      // Do some client specific processing
  #endif

      // Do some common processing
    }
  }

Metadata in scripts

Metadata can be added before script class, interface, function, and global variable declarations. The metadata is removed from the script by the builder class and stored for post build lookup by the type id, function id, or variable index.

Exactly what the metadata looks like is up to the application. The builder class doesn't impose any rules, except that the metadata should be added between brackets []. After the script has been built the application can obtain the metadata strings and interpret them as it sees fit. Multiple metadata blocks, i.e. [], can be defined for each entity.

Example script with metadata:

  [factory func = CreateOgre]
  class COgre
  {
    [editable]
    vector3 myPosition;

    [editable]
    [range [10, 100]]
    int     myStrength;
  }

  [factory]
  COgre @CreateOgre()
  {
    return @COgre();
  }

Example usage:

CScriptBuilder builder;

int r = builder.StartNewModule(engine, "my module");

if( r >= 0 )

  r = builder.AddSectionFromMemory(script);

if( r >= 0 )

  r = builder.BuildModule();

if( r >= 0 )

{

  // Find global variables that have been marked as editable by user

  asIScriptModule *mod = engine->GetModule("my module");

  int count = mod->GetGlobalVarCount();

  for( int n = 0; n < count; n++ )

  {

    vector<string> metadata = builder.GetMetadataStringForVar(n);

    for( int m = 0; m < metadata.size(); m++ )

    {

      if( metadata[m] == "editable" )

      {

        // Show the global variable in a GUI

        ...

      }

    }

  }

}

asIScriptModule::GetGlobalVarCount

virtual asUINT GetGlobalVarCount() const =0

Returns the number of global variables in the module.

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Context manager</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Context manager

Path: /sdk/add_on/contextmgr/

The CContextMgr is a class designed to aid the management of multiple simultaneous scripts executing in parallel. It supports both concurrent script threads and co-routines.

If the application doesn't need multiple contexts, i.e. all scripts that are executed always complete before the next script is executed, then this class is not necessary.

The context manager uses asIScriptEngine::RequestContext to take advantage of any context callbacks registered with the engine, e.g. for debugging or pooling.

Multiple context managers can be used, for example when you have a group of scripts controlling in-game objects, and another group of scripts controlling GUI elements, then each of these groups may be managed by different context managers.

Observe that the context manager class hasn't been designed for multi-threading, so you need to be careful if your application needs to execute scripts from multiple threads.

See also

The samples Concurrent scripts and Co-routines for uses

Public C++ interface

class CContextMgr

{

public:

  CContextMgr();

  ~CContextMgr();

  // Set the function that the manager will use to obtain the time in milliseconds.

  void SetGetTimeCallback(TIMEFUNC_t func);

  // Registers the following:

  //

  //  void sleep(uint milliseconds)

  //

  // The application must set the get time callback for this to work

  void RegisterThreadSupport(asIScriptEngine *engine);

  // Registers the following:

  //

  //  funcdef void coroutine(dictionary@)

  //  void createCoRoutine(coroutine @func, dictionary @args)

  //  void yield()

  void RegisterCoRoutineSupport(asIScriptEngine *engine);

  // Create a new context, prepare it with the function, then return

  // it so that the application can pass the argument values. The context

  // will be released by the manager after the execution has completed.

  // Set keepCtxAfterExecution to true if the application needs to retrieve

  // information from the context after it the script has finished.

  asIScriptContext *AddContext(asIScriptEngine *engine, asIScriptContext *func, bool keepCtxAfterExecution = false);

  // If the context was kept after the execution, this method must be

  // called when the application is done with the context so it can be

  // returned to the pool for reuse.

  void DoneWithContext(asIScriptContext *ctx);

  // Create a new context, prepare it with the function, then return

  // it so that the application can pass the argument values. The context

  // will be added as a co-routine in the same thread as the currCtx.

  asIScriptContext *AddContextForCoRoutine(asIScriptContext *currCtx, asIScriptContext *func);

  // Execute each script that is not currently sleeping. The function returns after

  // each script has been executed once. The application should call this function

  // for each iteration of the message pump, or game loop, or whatever.

  // Returns the number of scripts still in execution.

  int ExecuteScripts();

  // Put a script to sleep for a while

  void SetSleeping(asIScriptContext *ctx, asUINT milliSeconds);

  // Switch the execution to the next co-routine in the group.

  // Returns true if the switch was successful.

  void NextCoRoutine();

  // Abort all scripts

  void AbortAll();

};

asUINT

unsigned int asUINT

32 bit unsigned integer

Definition: angelscript.h:610

asIScriptContext

The interface to the virtual machine.

Definition: angelscript.h:2735

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

Public script interface

See also

Co-routines

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: datetime object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

datetime object

Path: /sdk/add_on/datetime/

The CDateTime class provides a way for scripts to get the system date and time.

Register the type with the RegisterScriptDateTime(asIScriptEngine*) function.

Note

This class requires C++11 or later to compile.

Public C++ interface

class CDateTime

{

public:

  // Constructors

  CDateTime();

  CDateTime(const CDateTime &other);

  CDateTime(asUINT year, asUINT month, asUINT day, asUINT hour, asUINT minute, asUINT second);

  // Copy the stored value from another any object

  CDateTime &operator=(const CDateTime &other);

  // Accessors

  asUINT getYear() const;

  asUINT getMonth() const;

  asUINT getDay() const;

  asUINT getHour() const;

  asUINT getMinute() const;

  asUINT getSecond() const;

  // Setters

  // Returns true if valid

  bool setDate(asUINT year, asUINT month, asUINT day);

  bool setTime(asUINT hour, asUINT minute, asUINT second);

  // Operators

  // Return difference in seconds

  asINT64          operator-(const CDateTime &other) const;

  CDateTime        operator+(asINT64 seconds) const;

  friend CDateTime operator+(asINT64 seconds, const CDateTime &other);

  CDateTime &      operator+=(asINT64 seconds);

  CDateTime        operator-(asINT64 seconds) const;

  friend CDateTime operator-(asINT64 seconds, const CDateTime &other);

  CDateTime &      operator-=(asINT64 seconds);

  bool             operator==(const CDateTime &other) const;

  bool             operator<(const CDateTime &other) const;

};

asINT64

__int64 asINT64

64 bit integer

Definition: angelscript.h:630

asUINT

unsigned int asUINT

32 bit unsigned integer

Definition: angelscript.h:610

Public script interface

See also

datetime in the script language

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Debugger</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Debugger

Path: /sdk/add_on/debugger/

The CDebugger implements common debugging functionality for scripts, e.g. setting breakpoints, stepping through the code, examining values of variables, etc.

To use the debugger the line callback should be set in the context. This will allow the debugger to take over whenever a breakpoint is reached, so the script can be debugged.

By default the debugger uses the standard in and standard out streams to interact with the user, but this can be easily overloaded by deriving from the CDebugger class and implementing the methods TakeCommands and Output. With this it is possible to implement a graphical interface, or even remote debugging for an application.

The application developer may also be interested in registering to-string callbacks for registered types with calls to RegisterToStringCallback. Optionally the ToString method in the debugger can be overridden to implement custom to-string logic.

See also

The sample Command line runner for a complete example of how to use the debugger

Public C++ interface

class CDebugger

{

public:

  CDebugger();

  virtual ~CDebugger();

  // Register callbacks to handle to-string conversions of application types

  // The expandMembersLevel is a counter for how many recursive levels the members should be expanded.

  // If the object that is being converted to a string has members of its own the callback should call

  // the debugger's ToString passing in expandMembersLevel - 1.

  typedef std::string (*ToStringCallback)(void *obj, int expandMembersLevel, CDebugger *dbg);

  virtual void RegisterToStringCallback(const asITypeInfo *type, ToStringCallback callback);

  // User interaction

  virtual void TakeCommands(asIScriptContext *ctx);

  virtual void Output(const std::string &str);

  // Line callback invoked by context

  virtual void LineCallback(asIScriptContext *ctx);

  // Commands

  virtual void PrintHelp();

  virtual void AddFileBreakPoint(const std::string &file, int lineNbr);

  virtual void AddFuncBreakPoint(const std::string &func);

  virtual void ListBreakPoints();

  virtual void ListLocalVariables(asIScriptContext *ctx);

  virtual void ListGlobalVariables(asIScriptContext *ctx);

  virtual void ListMemberProperties(asIScriptContext *ctx);

  virtual void ListStatistics(asIScriptContext *ctx);

  virtual void PrintCallstack(asIScriptContext *ctx);

  virtual void PrintValue(const std::string &expr, asIScriptContext *ctx);

  // Helpers

  virtual bool InterpretCommand(const std::string &cmd, asIScriptContext *ctx);

  virtual bool CheckBreakPoint(asIScriptContext *ctx);

  virtual std::string ToString(void *value, asUINT typeId, int expandMembersLevel, asIScriptEngine *engine);

  // Optionally set the engine pointer in the debugger so it can be retrieved

  // by callbacks that need it. This will hold a reference to the engine.

  virtual void SetEngine(asIScriptEngine *engine);

  virtual asIScriptEngine *GetEngine();

};

asUINT

unsigned int asUINT

32 bit unsigned integer

Definition: angelscript.h:610

asIScriptContext

The interface to the virtual machine.

Definition: angelscript.h:2735

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

asITypeInfo

The interface for describing types This interface is used to describe the types in the script engine.

Definition: angelscript.h:3704

Example usage

CDebugger dbg;

int ExecuteWithDebug(asIScriptContext *ctx)

{

  // Tell the context to invoke the debugger's line callback

  ctx->SetLineCallback(asMETHOD(CDebugger, LineCallback), &dbg, asCALL_THISCALL);

  // Allow the user to initialize the debugging before moving on

  dbg.TakeCommands(ctx);

  // Execute the script normally. If a breakpoint is reached the

  // debugger will take over the control loop.

  return ctx->Execute();

}

asCALL_THISCALL

@ asCALL_THISCALL

A thiscall class method.

Definition: angelscript.h:236

asMETHOD

#define asMETHOD(c, m)

Returns an asSFuncPtr representing the class method specified by class and method name.

Definition: angelscript.h:750

asIScriptContext::Execute

virtual int Execute()=0

Executes the prepared function.

asIScriptContext::SetLineCallback

virtual int SetLineCallback(asSFuncPtr callback, void *obj, int callConv)=0

Sets a line callback function. The function will be called for each executed script statement.

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: dictionary object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

dictionary object

Path: /sdk/add_on/scriptdictionary/

The dictionary object maps string values to values or objects of other types.

Register with RegisterScriptDictionary(asIScriptEngine*).

Compile the add-on with the pre-processor define AS_USE_STLNAMES=1 to register the methods with the same names as used by C++ STL where the methods have the same significance. Not all methods from STL is implemented in the add-on, but many of the most frequent once are so a port from script to C++ and vice versa might be easier if STL names are used.

Public C++ interface

typedef std::string dictKey;

class CScriptDictionary

{

public:

  // Factory functions

  static CScriptDictionary *Create(asIScriptEngine *engine);

  // Reference counting

  void AddRef() const;

  void Release() const;

  // Perform a shallow copy of the other dictionary

  CScriptDictionary &operator=(const CScriptDictionary &other);

  // Sets a key/value pair

  void Set(const dictKey &key, void *value, int typeId);

  void Set(const dictKey &key, asINT64 &value);

  void Set(const dictKey &key, double &value);

  // Gets the stored value. Returns false if the value isn't compatible with informed type

  bool Get(const dictKey &key, void *value, int typeId) const;

  bool Get(const dictKey &key, asINT64 &value) const;

  bool Get(const dictKey &key, double &value) const;

  // Index accessors. If the dictionary is not const it inserts the value if it doesn't already exist

  // If the dictionary is const then a script exception is set if it doesn't exist and a null pointer is returned

  CScriptDictValue *operator[](const dictKey &key);

  const CScriptDictValue *operator[](const dictKey &key) const;

  // Returns the type id of the stored value, or negative if it doesn't exist

  int  GetTypeId(const dictKey &key) const;

  // Returns true if the key is set

  bool Exists(const dictKey &key) const;

  // Returns true if the dictionary is empty

  bool IsEmpty() const;

  // Returns the number of keys in the dictionary

  asUINT GetSize() const;

  // Deletes the key

  bool Delete(const dictKey &key);

  // Deletes all keys

  void DeleteAll();

  // Get an array of all keys

  CScriptArray *GetKeys() const;

  // STL style iterator

  class CIterator

  {

  public:

    void operator++();    // Pre-increment

    void operator++(int); // Post-increment

    bool operator==(const CIterator &other) const;

    bool operator!=(const CIterator &other) const;

    // Accessors

    const dictKey &GetKey() const;

    int            GetTypeId() const;

    bool           GetValue(asINT64 &value) const;

    bool           GetValue(double &value) const;

    bool           GetValue(void *value, int typeId) const;

    const void *   GetAddressOfValue() const;

  };

  CIterator begin() const;

  CIterator end() const;

  CIterator find(const dictKey &key) const;

};

asINT64

__int64 asINT64

64 bit integer

Definition: angelscript.h:630

asUINT

unsigned int asUINT

32 bit unsigned integer

Definition: angelscript.h:610

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

Public script interface

See also

Dictionaries in the script language

Example usage from C++

Here's a skeleton for iterating over the entries in the dictionary. For brevity the code doesn't show how to interpret the values, for more information on that see asETypeIdFlags and asIScriptEngine::GetTypeInfoById.

void iterateDictionary(CScriptDictionary *dict)

{

        // Iterate over each entry

        for (auto it : *dict)

        {

                // Determine the name of the key

                std::string keyName = it.GetKey();

                cout << "\"" << keyName << "\"" << " = ";

                // Get the type and address of the value

                int typeId = it.GetTypeId();

                const void *addressOfValue = it.GetAddressOfValue();

                // Cast the value to the correct C++ type according to the typeId and then print it

                ...

        }

}

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: file object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

file object

Path: /sdk/add_on/scriptfile/

This object provides support for reading and writing files.

Register with RegisterScriptFile(asIScriptEngine*).

If you do not want to provide write access for scripts then you can compile the add on with the define AS_WRITE_OPS 0, which will disable support for writing. This define can be made in the project settings or directly in the header.

Public C++ interface

class CScriptFile

{

public:

  // Constructor

  CScriptFile();

  // Memory management

  void AddRef() const;

  void Release() const;

  // Opening and closing file handles

  // mode = "r" -> open the file for reading

  // mode = "w" -> open the file for writing (overwrites existing files)

  // mode = "a" -> open the file for appending

  int Open(const std::string &filename, const std::string &mode);

  int Close();

  // Returns the size of the file

  int GetSize() const;

  // Returns true if the end of the file has been reached

  bool IsEOF() const;

  // Reads a specified number of bytes into the string

  std::string ReadString(unsigned int length);

  // Reads to the next new-line character

  std::string ReadLine();

  // Reads a signed integer

  asINT64     ReadInt(asUINT bytes);

  // Reads an unsigned integer

  asQWORD     ReadUInt(asUINT bytes);

  // Reads a float

  float       ReadFloat();

  // Reads a double

  double      ReadDouble();

  // Writes a string to the file

  int WriteString(const std::string &str);

  int WriteInt(asINT64 v, asUINT bytes);

  int WriteUInt(asQWORD v, asUINT bytes);

  int WriteFloat(float v);

  int WriteDouble(double v);

  // File cursor manipulation

  int GetPos() const;

  int SetPos(int pos);

  int MovePos(int delta);

  // Determines the byte order of the binary values (default: false)

  // Big-endian = most significant byte first

  bool mostSignificantByteFirst;

};

asQWORD

unsigned __int64 asQWORD

64 bit unsigned integer

Definition: angelscript.h:629

asINT64

__int64 asINT64

64 bit integer

Definition: angelscript.h:630

asUINT

unsigned int asUINT

32 bit unsigned integer

Definition: angelscript.h:610

Public script interface

See also

file

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: filesystem object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

filesystem object

Path: /sdk/add_on/scriptfile/

This object provides support for inspecting directories on the filesystem.

Register with RegisterScriptFileSystem(asIScriptEngine*).

Public C++ interface

class CScriptFileSystem

{

public:

  CScriptFileSystem();

  void AddRef() const;

  void Release() const;

  // Sets the current path that should be used in other calls when using relative paths

  // It can use relative paths too, so moving up a directory is used by passing in ".."

  bool ChangeCurrentPath(const std::string &path);

  std::string GetCurrentPath() const;

  // Returns true if the path is a directory. Input can be either a full path or a relative path.

  // This method does not return the dirs '.' and '..'

  bool IsDir(const std::string &path) const;

  // Returns true if the path is a link. Input can be either a full path or a relative path

  bool IsLink(const std::string &path) const;

  // Returns the size of file. Input can be either a full path or a relative path

  asINT64 GetSize(const std::string &path) const;

  // Returns a list of the files in the current path

  CScriptArray *GetFiles() const;

  // Returns a list of the directories in the current path

  CScriptArray *GetDirs() const;

  // Creates a new directory. Returns 0 on success

  int MakeDir(const std::string &path);

  // Removes a directory. Will only remove the directory if it is empty. Returns 0 on success

  int RemoveDir(const std::string &path);

  // Deletes a file. Returns 0 on success

  int DeleteFile(const std::string &path);

  // Copies a file. Returns 0 on success

  int CopyFile(const std::string &source, const std::string &target);

  // Moves or renames a file or directory. Returns 0 on success

  int Move(const std::string &source, const std::string &target);

  // Gets the date and time of the file/dir creation

  CDateTime GetCreateDateTime(const std::string &path) const;

  // Gets the date and time of the file/dir modification

  CDateTime GetModifyDateTime(const std::string &path) const;

};

asINT64

__int64 asINT64

64 bit integer

Definition: angelscript.h:630

Public script interface

See also

filesystem

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: grid template object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

grid template object

Path: /sdk/add_on/scriptgrid/

The grid type is a template object that allow the scripts to declare 2D grids of any type. In many ways it is similar to the array template object, but it is specialized for use with areas.

The type is registered with RegisterScriptGrid(asIScriptEngine *engine).

Public C++ interface

class CScriptGrid

{

public:

  // Set the memory functions that should be used by all CScriptGrids

  static void SetMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc);

  // Factory functions

  static CScriptGrid *Create(asITypeInfo *gridType);

  static CScriptGrid *Create(asITypeInfo *gridType, asUINT width, asUINT height);

  static CScriptGrid *Create(asITypeInfo *gridType, asUINT width, asUINT height, void *defaultValue);

  static CScriptGrid *Create(asITypeInfo *gridType, void *listBuffer);

  // Memory management

  void AddRef() const;

  void Release() const;

  // Type information

  asITypeInfo   *GetGridObjectType() const;

  int            GetGridTypeId() const;

  int            GetElementTypeId() const;

  // Size

  asUINT GetWidth() const;

  asUINT GetHeight() const;

  void   Resize(asUINT width, asUINT height);

  // Get a pointer to an element. Returns 0 if out of bounds

  void       *At(asUINT x, asUINT y);

  const void *At(asUINT x, asUINT y) const;

  // Set value of an element.

  // The value arg should be a pointer to the value that will be copied to the element.

  // Remember, if the grid holds handles the value parameter should be the

  // address of the handle. The refCount of the object will also be incremented

  void  SetValue(asUINT x, asUINT y, void *value);

};

asALLOCFUNC_t

void *(* asALLOCFUNC_t)(size_t)

The function signature for the custom memory allocation function.

Definition: angelscript.h:645

asUINT

unsigned int asUINT

32 bit unsigned integer

Definition: angelscript.h:610

asFREEFUNC_t

void(* asFREEFUNC_t)(void *)

The function signature for the custom memory deallocation function.

Definition: angelscript.h:647

asITypeInfo

The interface for describing types This interface is used to describe the types in the script engine.

Definition: angelscript.h:3704

Public script interface

  class grid<T>
  {
    grid();
    grid(uint width, uint height);
    grid(uint width, uint height, const T &in fillValue);

    uint width() const;
    uint height() const;
    void resize(uint w, uint h);

    T &opIndex(uint x, uint y);
    const T &opIndex(uint x, uint y) const;
  }

grid()

 grid(uint width, uint height)

 grid(uint width, height, const T &in fillValue)

The constructors initializes the grid object. The default constructor will create an zero sized grid.

uint width() const

 uint height() const

Returns the width and height of the grid.

void resize(uint w, uint h)

Resizes the grid to the new dimension. The elements that still fit in the grid will keep their values.

T &opIndex(uint x, uint y)

 const T &opIndex(uint x, uint y) const

The index operator returns a reference to one of the elements. If the index is out of bounds a script exception will be raised.

Example usage in script

  // Initialize a 5x5 map
  grid<int> map = {{1,0,1,1,1},
                   {0,0,1,0,0},
                   {0,1,1,0,1},
                   {0,1,1,0,1},
                   {0,0,0,0,1}};

  // A function to verify if the next area is walkable
  bool canWalk(uint x, uint y)
  {
    // If the map in the destination is
    // clear, it is possible to wark there
    return map[x,y] == 0;
  }

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: ref object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

ref object

Path: /sdk/add_on/scripthandle/

The ref type is a generic container that can hold any handle. It is a value type, but behaves very much like an object handle.

The type is registered with RegisterScriptHandle(asIScriptEngine*).

See also

Registering a generic handle type

Public C++ interface

class CScriptHandle

{

public:

  // Constructors

  CScriptHandle();

  CScriptHandle(const CScriptHandle &other);

  CScriptHandle(void *ref, int typeId);

  ~CScriptHandle();

  // Copy the stored reference from another handle object

  CScriptHandle &operator=(const CScriptHandle &other);

  // Set the reference

  void Set(void *ref, asITypeInfo *type);

  // Compare equalness

  bool operator==(const CScriptHandle &o) const;

  bool operator!=(const CScriptHandle &o) const;

  bool opEquals(void *ref, int typeId) const;

  // Dynamic cast to desired handle type

  void Cast(void **outRef, int typeId);

  // Returns the type of the reference held

  asITypeInfo   *GetType() const;

  int            GetTypeId() const;

  // Returns the reference

  void *GetRef();

};

asITypeInfo

The interface for describing types This interface is used to describe the types in the script engine.

Definition: angelscript.h:3704

Public script interface

See also

ref in the script language

Example usage from C++

Even though the CScriptHandle is a value type, when registering properties of its type they should be registered as handles. The same goes for function arguments and return types.

CScriptHandle g_handle;

void Function(CScriptHandle handle)

{

  ... use the methods of CScriptHandle to determine the true object held in it

}

void Register(asIScriptEngine *engine)

{

  int r;

  r = engine->RegisterGlobalProperty("ref @g_handle", &g_handle); assert( r >= 0 );

  r = engine->RegisterGlobalFunction("void Function(ref @)", asFUNCTION(Function), asCALL_CDECL); assert( r >= 0 );

}

asCALL_CDECL

@ asCALL_CDECL

A cdecl function.

Definition: angelscript.h:230

asFUNCTION

#define asFUNCTION(f)

Returns an asSFuncPtr representing the function specified by the name.

Definition: angelscript.h:685

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

asIScriptEngine::RegisterGlobalFunction

virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary=0)=0

Registers a global function.

asIScriptEngine::RegisterGlobalProperty

virtual int RegisterGlobalProperty(const char *declaration, void *pointer)=0

Registers a global property.

To set an object pointer in the handle from the application, you'll use the Set() method passing a pointer to the object and the type of the object.

To retrieve an object pointer from the application you'll use the Cast() method passing in a pointer to the pointer and the wanted type id. If the type id given doesn't match the stored handle the returned pointer will be null.

To retrieve an object of an unknown type use the GetType() or GetTypeId() to determine the type stored in the handle, then use the Cast() method.

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Helper functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Helper functions

Path: /sdk/add_on/scripthelper/

These helper functions simplify the implementation of common tasks. They can be used as is or can serve as the starting point for your own framework.

Public C++ interface

// Compare relation between two objects of the same type.

// Uses the object's opCmp method to perform the comparison.

// Returns a negative value if the comparison couldn't be performed.

int CompareRelation(asIScriptEngine *engine, void *leftObj, void *rightObj, int typeId, int &result);

// Compare equality between two objects of the same type.

// Uses the object's opEquals method to perform the comparison, or if that doesn't exist the opCmp method.

// Returns a negative value if the comparison couldn't be performed.

int CompareEquality(asIScriptEngine *engine, void *leftObj, void *rightObj, int typeId, bool &result);

// Compile and execute simple statements.

// The module is optional. If given the statements can access the entities compiled in the module.

// The caller can optionally provide its own context, for example if a context should be reused.

int ExecuteString(asIScriptEngine *engine, const char *code, asIScriptModule *mod = 0, asIScriptContext *ctx = 0);

// Compile and execute simple statements with option of return value.

// The module is optional. If given the statements can access the entitites compiled in the module.

// The caller can optionally provide its own context, for example if a context should be reused.

int ExecuteString(asIScriptEngine *engine, const char *code, void *ret, int retTypeId, asIScriptModule *mod = 0, asIScriptContext *ctx = 0);

// Format the details of the script exception into a human readable text.

// Whenever the asIScriptContext::Execute method returns asEXECUTION_EXCEPTION, the application

// can call this function to get more information about that exception in a human readable form.

// The information obtained includes the current function, the script source section,

// program position in the source section, and the exception description itself.

std::string GetExceptionInfo(asIScriptContext *ctx, bool showStack = false);

// Write registered application interface to file.

// This function creates a file with the configuration for the offline compiler, asbuild, in the samples.

// If you wish to use the offline compiler you should call this function from you application after the

// application interface has been fully registered. This way you will not have to create the configuration

// file manually.

int WriteConfigToFile(asIScriptEngine *engine, const char *filename);

// Write the registered application interface to a text stream.

int WriteConfigToStream(asIScriptEngine *engine, std::ostream &strm);

// Loads an interface from a text stream and configures the engine with it. This will not

// set the correct function pointers, so it is not possible to use this engine to execute

// scripts, but it can be used to compile scripts and save the byte code.

int ConfigEngineFromStream(asIScriptEngine *engine, std::istream &strm, const char *nameOfStream = "config", asIStringFactory *stringFactory = 0);

asIScriptContext

The interface to the virtual machine.

Definition: angelscript.h:2735

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

asIScriptModule

The interface to the script modules.

Definition: angelscript.h:2232

asIStringFactory

The interface for the string factory.

Definition: angelscript.h:2164

Example

To compare two script objects the application can execute the following code:

void Compare(asIScriptObject *a, asIScriptObject *b)

{

  asIScriptEngine *engine = a->GetEngine();

  int typeId = a->GetTypeId();

  int cmp;

  int r = CompareRelation(engine, a, b, typeId, cmp);

  if( r < 0 )

  {

    cout << "The relation between a and b cannot be established b" << endl;

  }

  else

  {

    if( cmp < 0 )

      cout << "a is smaller than b" << endl;

    else if( cmp == 0 )

      cout << "a is equal to b" << endl;

    else

      cout << "a is greater than b" << endl;

  }

}

asIScriptObject

The interface for an instance of a script object.

Definition: angelscript.h:3590

asIScriptObject::GetTypeId

virtual int GetTypeId() const =0

Returns the type id of the object.

asIScriptObject::GetEngine

virtual asIScriptEngine * GetEngine() const =0

Return the script engine.

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Exception routines</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Exception routines

Path: /sdk/add_on/scripthelper/

The exception handling routines are registered by the application with a call to RegisterExceptionRoutines.

Public C++ interface

// Register the exception routines.

//  'void throw(const string &msg)'

//  'string getExceptionInfo()'

void RegisterExceptionRoutines(asIScriptEngine *engine);

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

Public script interface

See also

Exception handling

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: math functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

math functions

Path: /sdk/add_on/scriptmath/

This add-on registers the math functions from the standard C runtime library with the script engine. Use RegisterScriptMath(asIScriptEngine*) to perform the registration.

By defining the preprocessor word AS_USE_FLOAT=0, the functions will be registered to take and return doubles instead of floats.

The function RegisterScriptMathComplex(asIScriptEngine*) registers a type that represents a complex number, i.e. a number with real and imaginary parts.

Public script interface

  // Trigonometric functions
  float cos(float rad);
  float sin(float rad);
  float tan(float rad);

  // Inverse trigonometric functions
  float acos(float val);
  float asin(float val);
  float atan(float val);
  float atan2(float y, float x);

  // Hyperbolic functions
  float cosh(float rad);
  float sinh(float rad);
  float tanh(float rad);

  // Logarithmic functions
  float log(float val);
  float log10(float val);

  // Power to
  float pow(float val, float exp);

  // Square root
  float sqrt(float val);

  // Absolute value
  float abs(float val);

  // Ceil and floor functions
  float ceil(float val);
  float floor(float val);

  // Returns the fraction
  float fraction(float val);

  // Approximate float comparison, to deal with numeric imprecision
  bool closeTo(float a, float b, float epsilon = 0.00001f);
  bool closeTo(double a, double b, double epsilon = 0.0000000001);

  // Conversion between floating point and IEEE 754 representations
  float  fpFromIEEE(uint raw);
  double fpFromIEEE(uint64 raw);
  uint   fpToIEEE(float fp);
  uint64 fpToIEEE(double fp);

Functions

cos, sin, tan

Calculates the trigonometric functions cosine, sine, and tangent. The input angle should be given in radian.

acos, asin, atan

Calculates the inverse of the trigonometric functions cosine, sine, and tangent. The returned angle is given in radian.

atan2

Calculates the inverse of the trigonometric function tangent. The input is the y and x proportions. The returned angle is given in radian.

cosh, sinh, tanh

Calculates the hyperbolic of the cosine, sine, and tangent. The input angle should be given in radian.

log, log10

Calculates the logarithm of the input value. log is the natural logarithm and log10 is the base-10 logarithm.

pow

Calculates the based raised to the power of exponent.

sqrt

Calculates the square root of the value.

abs

Returns the absolute value.

ceil, floor

ceil returns the closest integer number that is higher or equal to the input. Floor returns the closest integer number that is lower or equal to the input.

fraction

Returns the fraction of the number, i.e. what remains after taking away the integral number.

closeTo

Due to numerical errors with the binary representation of real numbers it is often difficult to do direct comparisons of two float values. The closeTo function will return true of the two values are almost equal, allowing for a small difference up to the size of the epsilon value.

fpFromIEEE, fpToIEEE

Translates the float to and from IEEE 754 representation. This can be used if one wishes to directly inspect or manipulate the floating point value in the binary representation.

The complex type

  // This type represents a complex number with real and imaginary parts
  class complex
  {
    // Constructors
    complex();
    complex(const complex &in);
    complex(float r);
    complex(float r, float i);

    // Equality operator
    bool opEquals(const complex &in) const;

    // Compound assignment operators
    complex &opAddAssign(const complex &in);
    complex &opSubAssign(const complex &in);
    complex &opMulAssign(const complex &in);
    complex &opDivAssign(const complex &in);

    // Math operators
    complex opAdd(const complex &in) const;
    complex opSub(const complex &in) const;
    complex opMul(const complex &in) const;
    complex opDiv(const complex &in) const;

    // Returns the absolute value (magnitude)
    float abs() const;

    // Swizzle operators
    complex get_ri() const;
    void set_ri(const complex &in);
    complex get_ir() const;
    void set_ir(const complex &in);

    // The real and imaginary parts
    float r;
    float i;
  }

complex

The constructors allow for implicit construction, making a copy, implicit conversion from float, and explicit initialization from two float values.

=, !=

Compares two complex values.

=, +=, -=, *=, /=

Assign and compound assignment of complex values.

+, -, *, /

Math operators on complex values.

abs

Returns the absolute (magnitude) of the complex value.

r, i

Retrieves the real and imaginary part of the complex value.

ri, ir

Swizzle operators return a complex value with the ordering of the real and imaginary parts as indicated by the name.

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Script extensions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Script extensions

string object

array template object

any object

ref object

weakref object

dictionary object

file object

filesystem object

math functions

grid template object

datetime object

Exception routines

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
var doc_addon_script =
[
    [ "string object", "doc_addon_std_string.html", [
      [ "Public C++ interface", "doc_addon_std_string.html#doc_addon_std_string_1", null ],
      [ "Public script interface", "doc_addon_std_string.html#doc_addon_std_string_2", null ]
    ] ],
    [ "array template object", "doc_addon_array.html", [
      [ "Public C++ interface", "doc_addon_array.html#doc_addon_array_1", null ],
      [ "Public script interface", "doc_addon_array.html#doc_addon_array_2", null ],
      [ "C++ example", "doc_addon_array.html#doc_addon_array_4", null ]
    ] ],
    [ "any object", "doc_addon_any.html", [
      [ "Public C++ interface", "doc_addon_any.html#doc_addon_any_1", null ],
      [ "Public script interface", "doc_addon_any.html#doc_addon_any_2", null ],
      [ "Example usage", "doc_addon_any.html#doc_addon_any_3", null ]
    ] ],
    [ "ref object", "doc_addon_handle.html", [
      [ "Public C++ interface", "doc_addon_handle.html#doc_addon_handle_1", null ],
      [ "Public script interface", "doc_addon_handle.html#doc_addon_handle_3", null ],
      [ "Example usage from C++", "doc_addon_handle.html#doc_addon_handle_4", null ]
    ] ],
    [ "weakref object", "doc_addon_weakref.html", [
      [ "Public C++ interface", "doc_addon_weakref.html#doc_addon_weakref_1", null ],
      [ "Public script interface", "doc_addon_weakref.html#doc_addon_weakref_2", null ]
    ] ],
    [ "dictionary object", "doc_addon_dict.html", [
      [ "Public C++ interface", "doc_addon_dict.html#doc_addon_dict_1", null ],
      [ "Public script interface", "doc_addon_dict.html#doc_addon_dict_2", null ],
      [ "Example usage from C++", "doc_addon_dict.html#doc_addon_dict_3", null ]
    ] ],
    [ "file object", "doc_addon_file.html", [
      [ "Public C++ interface", "doc_addon_file.html#doc_addon_file_1", null ],
      [ "Public script interface", "doc_addon_file.html#doc_addon_file_2", null ]
    ] ],
    [ "filesystem object", "doc_addon_filesystem.html", [
      [ "Public C++ interface", "doc_addon_filesystem.html#doc_addon_filesystem_1", null ],
      [ "Public script interface", "doc_addon_filesystem.html#doc_addon_filesystem_2", null ]
    ] ],
    [ "math functions", "doc_addon_math.html", [
      [ "Public script interface", "doc_addon_math.html#doc_addon_math_1", [
        [ "Functions", "doc_addon_math.html#doc_addon_math_funcs", null ],
        [ "The complex type", "doc_addon_math.html#doc_addon_math_complex", null ]
      ] ]
    ] ],
    [ "grid template object", "doc_addon_grid.html", [
      [ "Public C++ interface", "doc_addon_grid.html#doc_addon_grid_1", null ],
      [ "Public script interface", "doc_addon_grid.html#doc_addon_grid_2", null ],
      [ "Example usage in script", "doc_addon_grid.html#doc_addon_grid_3", null ]
    ] ],
    [ "datetime object", "doc_addon_datetime.html", [
      [ "Public C++ interface", "doc_addon_datetime.html#doc_addon_datetime_1", null ],
      [ "Public script interface", "doc_addon_datetime.html#doc_addon_datetime_2", null ]
    ] ],
    [ "Exception routines", "doc_addon_helpers_try.html", [
      [ "Public C++ interface", "doc_addon_helpers_try.html#doc_addon_helpers_try_1", null ],
      [ "Public script interface", "doc_addon_helpers_try.html#doc_add_helpers_try_2", null ]
    ] ]
];


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Serializer</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Serializer

Path: /sdk/add_on/serializer/

The CSerializer implements support for serializing the values of global variables in a module, for example in order to reload a slightly modified version of the script without reinitializing everything. It will resolve primitives and script classes automatically, including references and handles.

For application registered types, the application needs to implement callback objects to show how these should be serialized. The exception is for pod types, as the serializer will simply keep a bitwise copy. Registered reference types without factories will not be serialized, i.e. the object will be kept as-is.

The implementation currently has some limitations:

It can only serialize to memory, i.e. it is not possible to save the values to a file.

If the variables changed type when restoring, the serializer cannot restore the value.

The serializer will attempt to backup all objects, but in some cases an application may not want to backup the actual object, but only a reference to it, e.g. an internal application object referenced by the script. Currently there is no way of telling the serializer to do differently in this case.

If the module holds references to objects from another module it will probably fail in restoring the values.

Public C++ interface

class CSerializer

{

public:

  CSerializer();

  ~CSerializer();

  // Clear the serializer to free references held internally

  void Clear();

  // Add implementation for serializing user types

  void AddUserType(CUserType *ref, const std::string &name);

  // Store all global variables in the module

  int Store(asIScriptModule *mod);

  // Restore all global variables after reloading script

  int Restore(asIScriptModule *mod);

  // Store extra objects that are not seen from the module's global variables

  void AddExtraObjectToStore(asIScriptObject *object);

  // Return new pointer to restored object

  void *GetPointerToRestoredObject(void *originalObject);

};

asIScriptModule

The interface to the script modules.

Definition: angelscript.h:2232

asIScriptObject

The interface for an instance of a script object.

Definition: angelscript.h:3590

Example usage

This first example shows how to serialize a script module that uses application registered types.

struct CStringType;

struct CArrayType;

void RecompileModule(asIScriptEngine *engine, asIScriptModule *mod)

{

  string modName = mod->GetName();

  // Tell the serializer how the user types should be serialized

  // by adding the implementations of the CUserType interface

  CSerializer backup;

  backup.AddUserType(new CStringType(), "string");

  backup.AddUserType(new CArrayType(), "array");

  // Backup the values of the global variables

  backup.Store(mod);

  // Application can now recompile the module

  CompileModule(modName);

  // Restore the values of the global variables in the new module

  mod = engine->GetModule(modName.c_str(), asGM_ONLY_IF_EXISTS);

  backup.Restore(mod);

}

// This serializes the std::string type

struct CStringType : public CUserType

{

  void *AllocateUnitializedMemory(CSerializedValue* value)

  {

        // This must not be done for strings

        assert(false);

        return 0;

  }

  void Store(CSerializedValue *val, void *ptr)

  {

    val->SetUserData(new std::string(*(std::string*)ptr));

  }

  void Restore(CSerializedValue *val, void *ptr)

  {

    std::string *buffer = (std::string*)val->GetUserData();

    *(std::string*)ptr = *buffer;

  }

  void CleanupUserData(CSerializedValue *val)

  {

    std::string *buffer = (std::string*)val->GetUserData();

    delete buffer;

  }

};

// This serializes the CScriptArray type

struct CArrayType : public CUserType

{

  void* AllocateUnitializedMemory(CSerializedValue* value)

  {

        CScriptArray* arr = CScriptArray::Create(value->GetType());

        return arr;

  }

  void Store(CSerializedValue *val, void *ptr)

  {

    CScriptArray *arr = (CScriptArray*)ptr;

    for( unsigned int i = 0; i < arr->GetSize(); i++ )

      val->m_children.push_back(new CSerializedValue(val ,"", "", arr->At(i), arr->GetElementTypeId()));

  }

  void Restore(CSerializedValue *val, void *ptr)

  {

    CScriptArray *arr = (CScriptArray*)ptr;

    arr->Resize(asUINT(val->m_children.size()));

    for( size_t i = 0; i < val->m_children.size(); ++i )

      val->m_children[i]->Restore(arr->At(asUINT(i)), arr->GetElementTypeId());

  }

};

asUINT

unsigned int asUINT

32 bit unsigned integer

Definition: angelscript.h:610

asGM_ONLY_IF_EXISTS

@ asGM_ONLY_IF_EXISTS

Don't return any module if it is not found.

Definition: angelscript.h:530

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

asIScriptEngine::GetModule

virtual asIScriptModule * GetModule(const char *module, asEGMFlags flag=asGM_ONLY_IF_EXISTS)=0

Return an interface pointer to the module.

asIScriptModule::GetName

virtual const char * GetName() const =0

Gets the name of the module.

The following example shows how to serialize additional objects, not stored in the module itself.

// This object is stored outside of the module, so it has to be explicitly informed to the serializer

asIScriptObject *scriptObj = reinterpret_cast<asIScriptObject*>(engine->CreateScriptObject(mod->GetTypeInfoByName("CTest")));

void RecompileModule(asIScriptEngine *engine, asIScriptModule *mod)

{

  string modName = mod->GetName();

  // Tell the serializer about the additional object stored outside of the module

  CSerializer backup;

  backup.AddExtraObjectToStore(scriptObj);

  // Backup the values of the global variables and the additional object

  r = backup.Store(mod);

  if( r < 0 )

    TEST_FAILED;

  // Application can now recompile the module

  CompileModule(modName);

  // Restore the values of the global variables in the new module

  mod = engine->GetModule(modName.c_str(), asGM_ONLY_IF_EXISTS);

  backup.Restore(mod);

  // Restore the extra object by looking up the new instance using the address of the old instance as key

  asIScriptObject *obj2 = (asIScriptObject*)backup.GetPointerToRestoredObject(scriptObj);

  scriptObj->Release();

  scriptObj = obj2;

  scriptObj->AddRef();

}

asIScriptEngine::CreateScriptObject

virtual void * CreateScriptObject(const asITypeInfo *type)=0

Creates an object defined by its type.

asIScriptModule::GetTypeInfoByName

virtual asITypeInfo * GetTypeInfoByName(const char *name) const =0

Returns the type interface by name.

asIScriptObject::AddRef

virtual int AddRef() const =0

Increase reference counter.

asIScriptObject::Release

virtual int Release() const =0

Decrease reference counter.

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: string object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

string object

Path: /sdk/add_on/scriptstdstring/

This add-on registers the std::string type as-is with AngelScript. This gives perfect compatibility with C++ functions that use std::string in parameters or as return type.

A potential drawback is that the std::string type is a value type, thus may increase the number of copies taken when string values are being passed around in the script code. However, this is most likely only a problem for scripts that perform a lot of string operations.

Register the type with RegisterStdString(asIScriptEngine*). Register the optional split method and global join function with RegisterStdStringUtils(asIScriptEngine*). The optional functions require that the array template object has been registered first.

Compile the add-on with the pre-processor define AS_USE_STLNAMES=1 to register the methods with the same names as used by C++ STL where the methods have the same significance. Not all methods from STL is implemented in the add-on, but many of the most frequent ones are so a port from script to C++ and vice versa might be easier if STL names are used.

Compile the add-on with the pre-processor define AS_USE_ACCESSORS=1 to register length as a virtual property instead of the method length().

Public C++ interface

Refer to the std::string implementation for your compiler.

Public script interface

See also

Strings in the script language

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: weakref object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

weakref object

Path: /sdk/add_on/weakref/

The weakref type is a template type for holding weak references to objects, i.e. the references that will not keep the referred object alive.

The type is registered with RegisterScriptWeakRef(asIScriptEngine*).

See also

Weak references

Public C++ interface

class CScriptWeakRef

{

public:

  // Constructors

  CScriptWeakRef(asITypeInfo *type);

  CScriptWeakRef(const CScriptWeakRef &other);

  CScriptWeakRef(void *ref, asITypeInfo *type);

  ~CScriptWeakRef();

  // Copy the stored value from another weakref object

  CScriptWeakRef &operator=(const CScriptWeakRef &other);

  // Compare equalness

  bool operator==(const CScriptWeakRef &o) const;

  bool operator!=(const CScriptWeakRef &o) const;

  // Sets a new reference

  CScriptWeakRef &Set(void *newRef);

  // Returns the object if it is still alive

  // This will increment the refCount of the returned object

  void *Get() const;

  // Returns true if the contained reference is the same

  bool Equals(void *ref) const;

  // Returns the type of the reference held

  asITypeInfo *GetRefType() const;

};

asITypeInfo

The interface for describing types This interface is used to describe the types in the script engine.

Definition: angelscript.h:3704

Public script interface

See also

weakref in the script language

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Access masks and exposing different interfaces</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Access masks and exposing different interfaces

An application may need to expose different interfaces to different types of scripts, e.g. a game entity may only have access to specific set of functions, while the GUI script can have access to a completely different set of functions.

To accomplish this the application can set a bitmask while registering the interface, and then use that bitmask when building the scripts to determine what the scripts should or should not be able to access.

void ConfigureEngine(asIScriptEngine *engine)

{

  // Register the interface available to script type 1

  engine->SetDefaultAccessMask(0x1);

  r = engine->RegisterGlobalFunction("void func1()", asFUNCTION(func1), asCALL_CDECL); assert( r >= 0 );

  // Register the interface available to script type 2

  engine->SetDefaultAccessMask(0x2);

  r = engine->RegisterGlobalFunction("void func2()", asFUNCTION(func2), asCALL_CDECL); assert( r >= 0 );

  // Register the interface available to both script types

  engine->SetDefaultAccessMask(0x3);

  r = engine->RegisterGlobalFunction("void func3()", asFUNCTION(func3), asCALL_CDECL); assert( r >= 0 );

}

int CompileScript(asIScriptEngine *engine, const char *script, int type)

{

  int r;

  CScriptBuilder builder;

  r = builder.StartNewModule(engine, script);

  if( r < 0 ) return r;

  // Set the access mask for the module, which will

  // determine the functions from the application

  // interface that can be called

  asIScriptModule *mod = builder.GetModule();

  mod->SetAccessMask(type);

  // Add the script section and build the script

  r = builder.AddSectionFromFile(script);

  if( r < 0 ) return r;

  return builder.BuildModule();

}

asCALL_CDECL

@ asCALL_CDECL

A cdecl function.

Definition: angelscript.h:230

asFUNCTION

#define asFUNCTION(f)

Returns an asSFuncPtr representing the function specified by the name.

Definition: angelscript.h:685

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

asIScriptEngine::RegisterGlobalFunction

virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary=0)=0

Registers a global function.

asIScriptEngine::SetDefaultAccessMask

virtual asDWORD SetDefaultAccessMask(asDWORD defaultMask)=0

Sets the access mask that should be used for subsequent registered entities.

asIScriptModule

The interface to the script modules.

Definition: angelscript.h:2232

asIScriptModule::SetAccessMask

virtual asDWORD SetAccessMask(asDWORD accessMask)=0

Sets the access mask that should be used during the compilation.

The access mask can be defined for the following entities in the application interface:

Global functions

Global properties

Object types

Individual methods of types

Individual properties of types

Individual object behaviours

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6


code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Class hierarchies</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="navtree.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

AngelScript

          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Loading...

Searching...

No Matches

Class hierarchies

AngelScript cannot automatically determine relationships between registered classes, so in order to establish the hierarchies for use within the script language it is necessary to do a bit more registration beyond the normal object registration.

Hierarchies can currently only be registered for reference types, not for value types.

Establishing the relationship

In order to let AngelScript know that two types are related you need to register the reference cast operators opCast and opImplCast. The opCast should be used if you only want to allow the cast through an explicit call with the cast<class> operator. opImplCast should be used when you want to allow the compiler to implicitly perform the cast as necessary.

Usually you'll want to use opImplCast for casts from a derived type to the base type, and opCast for casts from a base type to a derived type.

// Example opCast behaviour

template<class A, class B>

B* refCast(A* a)

{

    // If the handle already is a null handle, then just return the null handle

    if( !a ) return 0;

    // Now try to dynamically cast the pointer to the wanted type

    B* b = dynamic_cast<B*>(a);

    if( b != 0 )

    {

        // Since the cast was made, we need to increase the ref counter for the returned handle

        b->addref();

    }

    return b;

}

// Example registration of the behaviour

r = engine->RegisterObjectMethod("base", "derived@ opCast()", asFUNCTION((refCast<base,derived>)), asCALL_CDECL_OBJLAST); assert( r >= 0 );

r = engine->RegisterObjectMethod("derived", "base@ opImplCast()", asFUNCTION((refCast<derived,base>)), asCALL_CDECL_OBJLAST); assert( r >= 0 );

// Also register the const overloads so the cast works also when the handle is read only

r = engine->RegisterObjectMethod("base", "const derived@ opCast() const", asFUNCTION((refCast<base,derived>)), asCALL_CDECL_OBJLAST); assert( r >= 0 );

r = engine->RegisterObjectMethod("derived", "const base@ opImplCast() const", asFUNCTION((refCast<derived,base>)), asCALL_CDECL_OBJLAST); assert( r >= 0 );

asCALL_CDECL_OBJLAST

@ asCALL_CDECL_OBJLAST

A cdecl function that takes the object pointer as the last parameter.

Definition: angelscript.h:238

asFUNCTION

#define asFUNCTION(f)

Returns an asSFuncPtr representing the function specified by the name.

Definition: angelscript.h:685

Note that it may be necessary to add extra parenthesis to the asFUNCTION macro so that the preprocessor doesn't interpret the , in the template declaration as the argument separator in the macro.

Inherited methods and properties

Just as relationships cannot be determined, there is also no way to automatically let AngelScript add inherited methods and properties to derived types. The reason for this is that method pointers and property offsets may differ between the base class and derived class, especially when multiple inheritance is used, and there is no way to automatically determine exactly what the difference is.

For this reason the application needs to register all the inherited methods and properties for the derived classes, which may lead to a bit of duplicate code. However, you may be able to avoid the duplication through a bit of clever thinking. Here is an example of registering the methods and properties for a base class and the derived class (registration of behaviours has been omitted for briefness):

Observe that this way of doing it is not possible if the derived type hides members of the base type. If this is the case, then there is no option but to register each visible member in the derived type explicitly, excluding the hidden members of the base type.

// The base class

class base

{

public:

  virtual void aMethod();

  int aProperty;

};

// The derived class

class derived : public base

{

public:

  virtual void aNewMethod();

  int aNewProperty;

};

// The code to register the classes

// This is implemented as a template function, to support multiple inheritance

template <class T>

void RegisterBaseMembers(asIScriptEngine *engine, const char *type)

{

  int r;

  r = engine->RegisterObjectMethod(type, "void aMethod()", asMETHOD(T, aMethod), asCALL_THISCALL); assert( r >= 0 );

  r = engine->RegisterObjectProperty(type, "int aProperty", asOFFSET(T, aProperty)); assert( r >= 0 );

}

template <class T>

void RegisterDerivedMembers(asIScriptEngine *engine, const char *type)

{

  int r;

  // Register the inherited members by calling

  // the registration of the base members

  RegisterBaseMembers<T>(engine, type);

  // Now register the new members

  r = engine->RegisterObjectMethod(type, "void aNewMethod()", asMETHOD(T, aNewMethod), asCALL_THISCALL); assert( r >= 0 );

  r = engine->RegisterObjectProperty(type, "int aNewProperty", asOFFSET(T, aNewProperty)); assert( r >= 0 );

}

void RegisterTypes(asIScriptEngine *engine)

{

  int r;

  // Register the base type

  r = engine->RegisterObjectType("base", 0, asOBJ_REF); assert( r >= 0 );

  RegisterBaseMembers<base>(engine, "base");

  // Register the derived type

  r = engine->RegisterObjectType("derived", 0, asOBJ_REF); assert( r >= 0 );

  RegisterDerivedMembers<derived>(engine, "derived");

}

asCALL_THISCALL

@ asCALL_THISCALL

A thiscall class method.

Definition: angelscript.h:236

asOFFSET

#define asOFFSET(s, m)

Returns the offset of an attribute in a struct.

Definition: angelscript.h:682

asMETHOD

#define asMETHOD(c, m)

Returns an asSFuncPtr representing the class method specified by class and method name.

Definition: angelscript.h:750

asOBJ_REF

@ asOBJ_REF

A reference type.

Definition: angelscript.h:254

asIScriptEngine

The engine interface.

Definition: angelscript.h:1102

asIScriptEngine::RegisterObjectProperty

virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset, int compositeOffset=0, bool isCompositeIndirect=false)=0

Registers a property for the object type.

asIScriptEngine::RegisterObjectType

virtual int RegisterObjectType(const char *obj, int byteSize, asDWORD flags)=0

Registers a new object type.

asIScriptEngine::RegisterObjectMethod

virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary=0, int compositeOffset=0, bool isCompositeIndirect=false)=0

Registers a method for the object type.

Generated on Sun May 21 2023 10:12:39 for AngelScript by  1.9.6