Qore Programming Language Reference Manual
1.7.0
|
Program objects allow Qore programs to support subprograms with the option to restrict capabilities, for example, to support user-defined logic for application actions. More...
Public Member Methods | |
auto | callFunction (string name,...) |
Calls a function in the program object and returns the return value. More... | |
auto | callFunctionArgs (string name, *softlist< auto > vargs) |
Calls a function in the program object giving the arguments to the function as a list and returns the return value. More... | |
auto | callStaticMethod (string class_name, string method,...) |
Calls a static method of an object, passing the arguments to the function as arguments to the method. More... | |
auto | callStaticMethodArgs (string class_name, string method, *softlist< auto > call_args) |
Calls a static method of an object, passing the arguments to the function as arguments to the method. More... | |
constructor (softint po=PO_DEFAULT) | |
Creates the program object and optionally sets program capabilities (parse options) More... | |
copy () | |
Throws an exception to prevent objects of this class from being copied. More... | |
nothing | define (string def, auto val) |
Sets a parse define for the current Program. More... | |
destructor () | |
Waits for all threads to finish executing, then deletes all global variables, dereferences the internal Program object and deletes the Qore object. | |
nothing | disableParseOptions (softint opt) |
Removes the given parse options to the current parse option mask. More... | |
bool | existsFunction (string name) |
Checks if a user function exists in the program object. More... | |
list< hash< auto > > | findFunctionVariants (string function) |
finds all variants of a function or class method and returns a list of the results More... | |
*hash< auto > | getAllDefines () |
Retrieves all parse defines in the current Program. More... | |
code | getCallReference (string identifier) |
resolve the string as a call reference in the given Program More... | |
auto | getDefine (string def) |
Retrieves the value of the given parse define in the current Program. More... | |
Expression | getExpression (string source, string label) |
returns an expression object for the given source code More... | |
list< string > | getFeatureList () |
Returns a list of strings of the builtin and module-supplied features of Qore. More... | |
auto | getGlobalVariable (string varname, *reference< bool > rexists) |
Returns a the value of the global variable identified by the first string argument. More... | |
hash< auto > | getGlobalVars () |
returns a hash of global variables More... | |
list< string > | getParseOptionStringList () |
returns a list of parse option strings for the program object More... | |
int | getParseOptions () |
Returns the current binary-or'ed parse option mask for the Program object. More... | |
ProgramControl | getProgram () |
Get ProgramControl. More... | |
int | getProgramId () |
Get program id. More... | |
*string | getScriptDir () |
Returns the current script directory as a string or NOTHING if not set. More... | |
*string | getScriptName () |
Returns the current script name as a string or NOTHING if not set. More... | |
*string | getScriptPath () |
Returns the current script directory and filename if known, otherwise returns NOTHING. More... | |
list< int > | getThreadList () |
returns a list of thread IDs active in this Program More... | |
TimeZone | getTimeZone () |
Returns the default local time zone for the object. More... | |
softlist< string > | getUserFunctionList () |
Returns a list of strings of all user functions defined in the program object. More... | |
nothing | importClass (string cls, *string new_name, *softbool inject, int module_visibility=CSP_UNCHANGED) |
Imports a class into the program object's space; any calls to the imported class's code will run with the parent Program object's permissions. More... | |
nothing | importFunction (string func) |
Imports a function into the program object's space; any calls to the imported function will run with the parent Program object's permissions. More... | |
nothing | importFunction (string func, string new_name, *softbool inject) |
Imports a function into the program object's space and gives it a new name; any calls to the imported function will run with the parent Program object's permissions. More... | |
nothing | importGlobalVariable (string varname, bool readonly=False) |
Imports a global variable into the program object's space. More... | |
nothing | importHashDecl (string name, *string new_name) |
Imports a typed hash declaration into the program object's space. More... | |
importSystemApi () | |
imports system classes and functions into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_FUNC_VARIANTS, Qore::PO_NO_INHERIT_SYSTEM_HASHDECLS, Qore::PO_NO_INHERIT_SYSTEM_CONSTANTS, and Qore::PO_NO_INHERIT_SYSTEM_CLASSES More... | |
importSystemClasses () | |
imports system classes into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_CLASSES More... | |
importSystemConstants () | |
imports system constants into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_CONSTANTS More... | |
importSystemFunctions () | |
imports system functions into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_FUNC_VARIANTS More... | |
importSystemHashDecls () | |
imports system hashdecls into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_HASHDECLS More... | |
bool | isDefined (string def) |
Returns True if the given parse define is defined in the current Program (does not have to have a value defined to return True), False if not. More... | |
nothing | issueModuleCmd (string module, string cmd) |
issues a module command for the given module; the module is loaded into the current Program object if it is not already present More... | |
loadApplyToPrivateUserModule (string name, int warning_mask=WARN_MODULES) | |
Loads a Qore user module privately into the given Program container at run-time; after this call the Program object is owned by the user module and is no longer accessible in the object used for the call. More... | |
*hash< ExceptionInfo > | loadApplyToPrivateUserModuleWarn (string name, int warning_mask=WARN_MODULES) |
Loads a Qore user module privately into the given Program container at run-time; after this call the Program object is owned by the user module and is no longer accessible in the object used for the call. More... | |
loadApplyToUserModule (string name, *softbool reinject, int warning_mask=WARN_MODULES, bool reexport=False) | |
Loads a Qore user module into the given Program container at run-time; after this call the Program object is owned by the user module and is no longer accessible in the object used for the call. More... | |
*hash< ExceptionInfo > | loadApplyToUserModuleWarn (string name, *softbool reinject, int warning_mask=WARN_MODULES, bool reexport=False) |
Loads a Qore user module into the given Program container at run-time; after this call the Program object is owned by the user module and is no longer accessible in the object used for the call. More... | |
loadModule (string name, int warning_mask=WARN_MODULES) | |
Loads a Qore module into the Program object at run-time. More... | |
*hash< ExceptionInfo > | loadModuleWarn (string name, int warning_mask=WARN_MODULES) |
Loads a Qore module into the Program object at run-time. More... | |
loadUserModuleWithProgram (string name, Qore::Program pgm, int warning_mask=WARN_MODULES) | |
Loads a Qore user module into the Program object at run-time using the given Program object as the container for the user module code. More... | |
*hash< ExceptionInfo > | loadUserModuleWithProgramWarn (string name, Qore::Program pgm, int warning_mask=WARN_MODULES) |
Loads a Qore user module into the Program object at run-time using the given Program object as the container for the user module code. More... | |
nothing | lockOptions () |
Locks parse options so that they cannot be changed. More... | |
*hash< ExceptionInfo > | parse (string code, string label, *softint warning_mask, *string source, *softint offset, softbool format_label=True) |
Parses the string argument and adds the code to the Program object. More... | |
nothing | parseCommit () |
Commits and pending code processed with Program::parsePending() to the Program object after resolving all outstanding references in the pending code. More... | |
*hash< ExceptionInfo > | parseCommit (int warning_mask) |
Commits and pending code processed with Program::parsePending() to the Program object after resolving all outstanding references in the pending code. More... | |
*hash< ExceptionInfo > | parsePending (string code, string label, *softint warning_mask, *string source, *softint offset, softbool format_label=True) |
Parses the text passed to pending lists in the Program object; does not resolve all references or commit the code to the Program object. More... | |
nothing | parseRollback () |
Removes all partially or fully-parsed code from the object along with other builtin objects; a Program object is not usable after calling this method; do not use this method but instead destroy the Program object. More... | |
nothing | replaceParseOptions (softint opt) |
Replaces the parse options for the Program object. More... | |
auto | run () |
Runs the program and optionally returns a value if the top-level code exits with a return statement. More... | |
nothing | setGlobalVarValue (string name, auto value) |
set the value of a global variable More... | |
nothing | setParseOptions (softint opt=PO_DEFAULT) |
Sets parse options in the parse option mask for the Program object. More... | |
nothing | setScriptPath (*string path) |
Sets (or clears) the script path (directory and filename) for the object. More... | |
bool | setThreadInit (*code init) |
Sets a call reference or closure to run every time a new thread is started. More... | |
nothing | setTimeZone (TimeZone zone) |
Sets the default local time zone for the object. More... | |
nothing | setTimeZoneRegion (string region) |
Sets the default local time zone for the object from a path to a zoneinfo time zone region file. More... | |
nothing | setTimeZoneUTCOffset (softint seconds_east) |
Sets the default time zone for the Program object based on the number of seconds east of UTC; for zones west of UTC, use negative numbers. More... | |
nothing | undefine (string def) |
Unsets a parse define for the current Program. More... | |
Program objects allow Qore programs to support subprograms with the option to restrict capabilities, for example, to support user-defined logic for application actions.
Parsing in Qore happens in two steps; first all code is parsed to pending data structures, and then in the second stage, all references are resolved, and, if there are no errors, then all changes are committed to the Program object. Note that all parse actions (Program::parse(), Program::parsePending(), Program::parseCommit(), and Program::parseRollback()) are atomic; there is a thread lock on each Program object to ensure atomicity, and if any parse errors occur in any stage of parsing, any pending changes to the Program object are automatically rolled back. However parse actions that affect only one stage of the two stages of parsing (Program::parsePending(), Program::parseCommit() and Program::parseRollback()) are atomic within themselves, but not between calls, so one thread may inadvertently commit changes to a Program object if two or more threads are trying to perform transaction-safe two-stage parsing on a Program object without explicit user locking.
A complete parse action (Program::parse() or Program::parseCommit()) can only be performed once; subsequent attempts to parse code into the same Program object will fail with an exception. If parsing fails due to a parse exception, the Program object is generally no longer usable and must be recreated to be used.
Parse option constants can be used to limit the capabilities of a Program object. These options should be binary-OR'ed together and passed to the Program object's constructor. Also see qore Executable Command-Line Processing for equivalent command-line options, and Parse Directives for equivalent parse directives.
Note that a program can provide controlled access to functionality otherwise restricted by parse options by exporting a custom API into the child program object using either the Program::importFunction() or Program::importGlobalVariable() method. This is possible because code (functions or object methods) imported into and called from a subprogram will run in the parent's space and therefore with the parent's capabilities.
Classes, constants, namespaces, functions, and global variables are only inherited into child Program objects if they are declared public and no parse options prohibit it.
Symbols can also be imported into Program objects singly using methods such as Program::importClass() and Program::importGlobalVariable(), etc.
auto Qore::Program::callFunction | ( | string | name, |
... | |||
) |
Calls a function in the program object and returns the return value.
The function runs with the permissions of the Program object containing the function.
name | The name of the function to call |
... | The remaining arguments passed to the method are passed to the function to be called |
INVALID-FUNCTION-ACCESS | Parse options do not allow this builtin function to be called |
NO-FUNCTION | The function does not exist |
ENCODING-CONVERSION-ERROR | the function name could not be converted to the default character encoding |
auto Qore::Program::callFunctionArgs | ( | string | name, |
*softlist< auto > | vargs | ||
) |
Calls a function in the program object giving the arguments to the function as a list and returns the return value.
The function runs with the permissions of the Program object containing the function.
name | The name of the function to call |
vargs | The arguments to the function to be called |
INVALID-FUNCTION-ACCESS | Parse options do not allow this builtin function to be called |
NO-FUNCTION | The function does not exist |
ENCODING-CONVERSION-ERROR | the function name could not be converted to the default character encoding |
Calls a static method of an object, passing the arguments to the function as arguments to the method.
class_name | the with an optional namespace prefix |
method | the static method to call |
... | any additional arguments to the method |
METHOD-DOES-NOT-EXIST | The named method does not exist in this class |
ILLEGAL-EXPLICIT-METHOD-CALL | The named method may not be called explicitly |
METHOD-IS-PRIVATE | The named method is private and therefore can only be called within the class |
BASE-CLASS-IS-PRIVATE | The named method is a member of a privately inherited base class |
auto Qore::Program::callStaticMethodArgs | ( | string | class_name, |
string | method, | ||
*softlist< auto > | call_args | ||
) |
Calls a static method of an object, passing the arguments to the function as arguments to the method.
class_name | the with an optional namespace prefix |
method | the static method to call |
call_args | any additional arguments to the method |
METHOD-DOES-NOT-EXIST | The named method does not exist in this class |
ILLEGAL-EXPLICIT-METHOD-CALL | The named method may not be called explicitly |
METHOD-IS-PRIVATE | The named method is private and therefore can only be called within the class |
BASE-CLASS-IS-PRIVATE | The named method is a member of a privately inherited base class |
Qore::Program::constructor | ( | softint | po = PO_DEFAULT | ) |
Creates the program object and optionally sets program capabilities (parse options)
Note that if PO_NO_CHILD_PO_RESTRICTIONS is not set in the parent Program when the new Program object is created, then the created Program object will have the parent's parse options added to its parse options as given by the argument to the constructor.
In other words, if PO_NO_CHILD_PO_RESTRICTIONS is not set, it's not possible to create a child Program object with fewer restrictions than the parent Program object (any attempt to do so will be silently ignored).
However, if PO_NO_CHILD_PO_RESTRICTIONS is set in the parent Program object, then the parse option argument to the constructor will be applied literally to the child object. Additionally in this case module-specific- program data is not imported into the child Program object.
ProgramControl provides internal Program data for debugging purposes.
Use the ProgramControl::getProgram() method to attach to the currently running program
po | A binary OR'ed product of parse options |
PROGRAM-OPTION-ERROR | invalid parse options used |
Qore::Program::copy | ( | ) |
Throws an exception to prevent objects of this class from being copied.
PROGRAM-COPY-ERROR | copying Program objects is currently unsupported |
nothing Qore::Program::define | ( | string | def, |
auto | val | ||
) |
Sets a parse define for the current Program.
def | The parse define to assign |
val | The value to assign to the define |
nothing Qore::Program::disableParseOptions | ( | softint | opt | ) |
Removes the given parse options to the current parse option mask.
An OPTIONS-LOCKED
exception is thrown if parse options have been locked (for example with Program::lockOptions())
opt | A single parse option or binary-or'ed combination of parse options to unset in the parse option mask for the object; any bit set in this argument will be unset (ie zeroed out or combined with inverse binary and) in the Program's parse option mask |
OPTIONS-LOCKED | Parse options have been locked and cannot be changed |
PROGRAM-OPTION-ERROR | invalid parse options used |
bool Qore::Program::existsFunction | ( | string | name | ) |
Checks if a user function exists in the program object.
name | The name of the function to check |
ENCODING-CONVERSION-ERROR | the function name could not be converted to the default character encoding |
finds all variants of a function or class method and returns a list of the results
function | the function or class method name; may also be namespace-justified |
desc:
a string description of the call which includes the name and the full text call signatureparams:
a QoreListNode object that gives the params in a format that can be used by ProgramControl::findFunctionStatementIdPROGRAM-ERROR | thrown if the function cannot be found |
*hash<auto> Qore::Program::getAllDefines | ( | ) |
Retrieves all parse defines in the current Program.
code Qore::Program::getCallReference | ( | string | identifier | ) |
resolve the string as a call reference in the given Program
identifier | the string to resolve; function or static class method, can include namespace path |
CALL-REFERENCE-ERROR
exception is thrownCALL-REFERENCE-ERROR | cannot resolve call reference; method not accessible in the calling context |
auto Qore::Program::getDefine | ( | string | def | ) |
Retrieves the value of the given parse define in the current Program.
ENCODING-CONVERSION-ERROR | this error is thrown if the string cannot be converted to the default character encoding |
Expression Qore::Program::getExpression | ( | string | source, |
string | label | ||
) |
returns an expression object for the given source code
source | The source to the expression |
label | the label for the expression |
Returns a list of strings of the builtin and module-supplied features of Qore.
auto Qore::Program::getGlobalVariable | ( | string | varname, |
*reference< bool > | rexists | ||
) |
Returns a the value of the global variable identified by the first string argument.
varname | The string name of the global variable to find, not including the leading "$" character |
rexists | An lvalue reference to a bool to determine if the global variable exists (because this method could return NOTHING when the variable exists as well as when it does not) |
"$"
symbol)hash<auto> Qore::Program::getGlobalVars | ( | ) |
returns a hash of global variables
int Qore::Program::getParseOptions | ( | ) |
returns a list of parse option strings for the program object
ProgramControl Qore::Program::getProgram | ( | ) |
int Qore::Program::getProgramId | ( | ) |
*string Qore::Program::getScriptDir | ( | ) |
Returns the current script directory as a string or NOTHING if not set.
Gets the script directory set with Program::setScriptPath(). This is the same value that will be returned in the Qore program code with the get_script_dir() function if called from within the Program.
"/"
on UNIX, "\\"
on Windows)*string Qore::Program::getScriptName | ( | ) |
Returns the current script name as a string or NOTHING if not set.
Gets the script filename set with Program::setScriptPath(). This is the same value that will be returned in the Qore program code with the get_script_name() function if called from within the Program.
*string Qore::Program::getScriptPath | ( | ) |
Returns the current script directory and filename if known, otherwise returns NOTHING.
Gets the script directory and filename set with Program::setScriptPath(). This is the same value that will be returned in the Qore program code with the get_script_path() function if called from within the Program.
TimeZone Qore::Program::getTimeZone | ( | ) |
Returns the default local time zone for the object.
softlist<string> Qore::Program::getUserFunctionList | ( | ) |
Returns a list of strings of all user functions defined in the program object.
nothing Qore::Program::importClass | ( | string | cls, |
*string | new_name, | ||
*softbool | inject, | ||
int | module_visibility = CSP_UNCHANGED |
||
) |
Imports a class into the program object's space; any calls to the imported class's code will run with the parent Program object's permissions.
This allows a user-defined API with greater capabilities than the embedded Program object to be imported into the embedded code.
cls | the name of the class to import into the Program object |
new_name | the name of the class in the imported Program object; can be a fully-qualified namespace path, in which case the namespace path will be created in the target Program object if necessary as well (ex: "Ns1::Ns2::MyClass" ) |
inject | if True then the imported class will be marked as a dependency injection and therefore will not be overritten by subsequent calls to Program::importSystemClasses(), Program::importSystemHashDecls(), Program::importSystemConstants(), Program::importSystemApi(), Program::loadApplyToPrivateUserModule(), or Program::loadApplyToUserModule(); note that for this call to succeed, the Program must have Qore::PO_ALLOW_INJECTION set |
module_visibility | see Import Visibility Constants for valid values |
CLASS-IMPORT-ERROR | Cannot import a class into the same Program object; class or namespace with this name already exists or the source class does not exist; injection indicated but Qore::PO_ALLOW_INJECTION not set |
ENCODING-CONVERSION-ERROR | the class name could not be converted to the default character encoding |
nothing Qore::Program::importFunction | ( | string | func | ) |
Imports a function into the program object's space; any calls to the imported function will run with the parent Program object's permissions.
This allows a user-defined API with greater capabilities than the embedded Program object to be imported into the embedded code.
func | the name of the function to import into the Program object |
FUNCTION-IMPORT-ERROR | Cannot import a function into the same Program object; function with this name already exists |
PROGRAM-IMPORTFUNCTION-NO-FUNCTION | The function does not exist |
ENCODING-CONVERSION-ERROR | the function name could not be converted to the default character encoding |
"Namespace::func"
) Imports a function into the program object's space and gives it a new name; any calls to the imported function will run with the parent Program object's permissions.
This allows a user-defined API with greater capabilities than the embedded Program object to be imported into the embedded code.
func | the name of the function to import into the Program object |
new_name | the name of the function as it will be known in the Program object once imported; can be a fully- qualified namespace path, in which case the namespace path will be created in the target Program object if necessary as well (ex: "Ns1::Ns2::my_func" ) |
inject | if True then the imported function will be marked as a dependency injection and therefore will not be overritten by subsequent calls to Program::importSystemFunctions(), Program::importSystemApi(), Program::loadApplyToPrivateUserModule(), or Program::loadApplyToUserModule(); note that for this call to succeed, the Program must have Qore::PO_ALLOW_INJECTION set |
FUNCTION-IMPORT-ERROR | Cannot import a function into the same Program object; function with this name already exists; target namespace does not exist; injection indicated but Qore::PO_ALLOW_INJECTION not set |
PROGRAM-IMPORTFUNCTION-NO-FUNCTION | The function does not exist |
ENCODING-CONVERSION-ERROR | the function name could not be converted to the default character encoding |
"Namespace::func"
)Imports a global variable into the program object's space.
If the variable is an object, then any methods called from the subprogram will run in the parent's space
varname | The name of the global variable without the "$" |
readonly | If this argument is True, then the variable will be imported read-only, and cannot be changed by the subprogram (note that if the imported |
PROGRAM-IMPORTGLOBALVARIABLE-EXCEPTION | The global variable does not exist in the source program, or the target variable already exists |
ENCODING-CONVERSION-ERROR | the global variablt name could not be converted to the default character encoding |
Imports a typed hash declaration into the program object's space.
This allows a user-defined API with greater capabilities than the embedded Program object to be imported into the embedded code.
name | the name of the typed hash declaration to import into the Program object |
new_name | the name of the typed hash declaration in the imported Program object; can be a fully-qualified namespace path, in which case the namespace path will be created in the target Program object if necessary as well (ex: "Ns1::Ns2::MyClass" ) |
HASHDECL-IMPORT-ERROR | Cannot import a hashdecl into the same Program object; conflict with an existing definition |
ENCODING-CONVERSION-ERROR | the hashdecl name could not be converted to the default character encoding |
Qore::Program::importSystemApi | ( | ) |
imports system classes and functions into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_FUNC_VARIANTS, Qore::PO_NO_INHERIT_SYSTEM_HASHDECLS, Qore::PO_NO_INHERIT_SYSTEM_CONSTANTS, and Qore::PO_NO_INHERIT_SYSTEM_CLASSES
IMPORT-SYSTEM-API-ERROR | objects already imported; parse options are locked on the Program object; conflicting object found; system API incorrectly imported; in case this exception is raised, the Program object will not contain the full system API and is most likely unusable |
Qore::Program::importSystemClasses | ( | ) |
imports system classes into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_CLASSES
IMPORT-SYSTEM-API-ERROR | objects already imported; parse options are locked on the Program object; conflicting object found; system API incorrectly imported; in case this exception is raised, the Program object will not contain the full system API and is most likely unusable |
Qore::Program::importSystemConstants | ( | ) |
imports system constants into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_CONSTANTS
IMPORT-SYSTEM-API-ERROR | objects already imported; parse options are locked on the Program object; conflicting object found; system API incorrectly imported; in case this exception is raised, the Program object will not contain the full system API and is most likely unusable |
Qore::Program::importSystemFunctions | ( | ) |
imports system functions into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_FUNC_VARIANTS
IMPORT-SYSTEM-API-ERROR | objects already imported; parse options are locked on the Program object; conflicting object found; system API incorrectly imported; in case this exception is raised, the Program object will not contain the full system API and is most likely unusable |
Qore::Program::importSystemHashDecls | ( | ) |
imports system hashdecls into a Program container at runtime; will throw an exception if the Program was not created with Qore::PO_NO_INHERIT_SYSTEM_HASHDECLS
IMPORT-SYSTEM-API-ERROR | objects already imported; parse options are locked on the Program object; conflicting object found; system API incorrectly imported; in case this exception is raised, the Program object will not contain the full system API and is most likely unusable |
bool Qore::Program::isDefined | ( | string | def | ) |
Returns True if the given parse define is defined in the current Program (does not have to have a value defined to return True), False if not.
def | The name of the define to check |
ENCODING-CONVERSION-ERROR | this error is thrown if the string cannot be converted to the default character encoding |
issues a module command for the given module; the module is loaded into the current Program object if it is not already present
module | the module name |
cmd | the command string to execute to be parsed by the module |
PARSE-COMMAND-ERROR | the module does not support commands |
Qore::Program::loadApplyToPrivateUserModule | ( | string | name, |
int | warning_mask = WARN_MODULES |
||
) |
Loads a Qore user module privately into the given Program container at run-time; after this call the Program object is owned by the user module and is no longer accessible in the object used for the call.
This method allows a user module to be privately loaded with a custom API already present in the user module's Program container.
name | the name or path of the user module to load |
warning_mask | the warning mask to use when loading the module; note that warnings are treated as errors |
LOAD-MODULE-ERROR | module cannot be loaded: binary modules cannot be loaded in Program containers, etc |
warning_mask
parameter *hash<ExceptionInfo> Qore::Program::loadApplyToPrivateUserModuleWarn | ( | string | name, |
int | warning_mask = WARN_MODULES |
||
) |
Loads a Qore user module privately into the given Program container at run-time; after this call the Program object is owned by the user module and is no longer accessible in the object used for the call.
This method allows a user module to be privately loaded with a custom API already present in the user module's Program container.
name | the name or path of the user module to load |
warning_mask | the warning mask to use when loading the module; any warnings will be returned in the return value |
LOAD-MODULE-ERROR | module cannot be loaded: binary modules cannot be loaded in Program containers, etc |
warning_mask
parameter Qore::Program::loadApplyToUserModule | ( | string | name, |
*softbool | reinject, | ||
int | warning_mask = WARN_MODULES , |
||
bool | reexport = False |
||
) |
Loads a Qore user module into the given Program container at run-time; after this call the Program object is owned by the user module and is no longer accessible in the object used for the call.
This method allows a user module to be loaded with a custom API already present in the user module's Program container.
name | the name or path of the user module to load |
reinject | if True then the module will be reloaded even if already loaded previously; if the module was not already loaded then it is loaded with this call |
warning_mask | the warning mask to use when loading the module; note that warnings are treated as errors |
reexport | reexport symbols from the imported module (only valid when used in a user module) |
LOAD-MODULE-ERROR | module cannot be loaded: binary modules cannot be loaded in Program containers, etc |
warning_mask
parameterreexport
parameter *hash<ExceptionInfo> Qore::Program::loadApplyToUserModuleWarn | ( | string | name, |
*softbool | reinject, | ||
int | warning_mask = WARN_MODULES , |
||
bool | reexport = False |
||
) |
Loads a Qore user module into the given Program container at run-time; after this call the Program object is owned by the user module and is no longer accessible in the object used for the call.
This method allows a user module to be loaded with a custom API already present in the user module's Program container.
name | the name or path of the user module to load |
reinject | if True then the module will be reloaded even if already loaded previously; if the module was not already loaded then it is loaded with this call |
warning_mask | the warning mask to use when loading the module; any warnings will be returned in the return value |
reexport | reexport symbols from the imported module (only valid when used in a user module) |
LOAD-MODULE-ERROR | module cannot be loaded: binary modules cannot be loaded in Program containers, etc |
warning_mask
parameterreexport
parameter Qore::Program::loadModule | ( | string | name, |
int | warning_mask = WARN_MODULES |
||
) |
Loads a Qore module into the Program object at run-time.
If a feature with the same name already exists, then this feature's code is imported into the current Program object if necessary and no further action is taken.
Note that modules providing objects resolved at parse time (classes, constants, functions, etc) must be loaded prior to parsing.
name | either a feature name (a module will be searched with this feature name) or a path to a module to load |
warning_mask | the warning mask to use when loading the module; note that warnings are treated as errors |
LOAD-MODULE-ERROR | module cannot be loaded: API incompatibility, module defines symbols already defined in the target object, etc |
warning_mask
parameter *hash<ExceptionInfo> Qore::Program::loadModuleWarn | ( | string | name, |
int | warning_mask = WARN_MODULES |
||
) |
Loads a Qore module into the Program object at run-time.
If a feature with the same name already exists, then this feature's code is imported into the current Program object if necessary and no further action is taken.
Note that modules providing objects resolved at parse time (classes, constants, functions, etc) must be loaded prior to parsing.
name | either a feature name (a module will be searched with this feature name) or a path to a module to load |
warning_mask | the warning mask to use when loading the module; any warnings will be returned in the return value |
LOAD-MODULE-ERROR | module cannot be loaded: API incompatibility, module defines symbols already defined in the target object, etc |
Qore::Program::loadUserModuleWithProgram | ( | string | name, |
Qore::Program | pgm, | ||
int | warning_mask = WARN_MODULES |
||
) |
Loads a Qore user module into the Program object at run-time using the given Program object as the container for the user module code.
This method allows a user module to be loaded with a custom API already present in the user module's Program container. If a feature with the same name already exists, then this feature's code is imported into the current Program object if necessary and no further action is taken.
Note that modules providing objects resolved at parse time (classes, constants, functions, etc) must be loaded prior to parsing.
name | the name or path of the user module to load |
pgm | the Program object to use as a container for the new user module, presumably this has a custom API that the user module can use; note that after this call the Program object will be owned by the user module, therefore the object itself will no longer be valid and any accesses to the object after this call will result in an exception |
warning_mask | the warning mask to use when loading the module; note that warnings are treated as errors |
LOAD-MODULE-ERROR | module cannot be loaded: binary modules cannot be loaded in Program containers, module defines symbols already defined in the target object, etc |
warning_mask
parameter *hash<ExceptionInfo> Qore::Program::loadUserModuleWithProgramWarn | ( | string | name, |
Qore::Program | pgm, | ||
int | warning_mask = WARN_MODULES |
||
) |
Loads a Qore user module into the Program object at run-time using the given Program object as the container for the user module code.
This method allows a user module to be loaded with a custom API already present in the user module's Program container. If a feature with the same name already exists, then this feature's code is imported into the current Program object if necessary and no further action is taken.
Note that modules providing objects resolved at parse time (classes, constants, functions, etc) must be loaded prior to parsing.
name | the name or path of the user module to load |
pgm | the Program object to use as a container for the new user module, presumably this has a custom API that the user module can use; note that after this call the Program object will be owned by the user module, therefore the object itself will no longer be valid and any accesses to the object after this call will result in an exception |
warning_mask | the warning mask to use when loading the module; any warnings will be returned in the return value |
LOAD-MODULE-ERROR | module cannot be loaded: binary modules cannot be loaded in Program containers, module defines symbols already defined in the target object, etc |
nothing Qore::Program::lockOptions | ( | ) |
Locks parse options so that they cannot be changed.
*hash<ExceptionInfo> Qore::Program::parse | ( | string | code, |
string | label, | ||
*softint | warning_mask, | ||
*string | source, | ||
*softint | offset, | ||
softbool | format_label = True |
||
) |
Parses the string argument and adds the code to the Program object.
This method causes both stages of parsing to be executed; if this method is successful, then the code parsed is committed to the Program object. This method is equivalent to calling Program::parsePending() and Program::parseCommit() in one atomic call.
If an exception occurs in this method, all pending code is backed out, not just code parsed by this method (for example, in case uncommitted code added by Program::parsePending() also exists in the Program object before calling this method).
code | The code to parse into the Program object |
label | The label for the code; this label will be given if any parse or run-time errors are raised for the code given |
warning_mask | An optional warning mask; see Warning Constants for values to combine by binary-or; if this argument is 0 or not given then no warnings will be checked or issued and the return value will always be NOTHING |
source | An optional source file name for the code being parsed; this is useful if sections of a file are parsed |
offset | An optional line offset for use with the source parameter; this gives the line offset in the file to the code being parsed |
format_label | obsolete / ignored since Qore 0.9 |
PROGRAM-PARSE-ERROR | this exception is thrown if any parse actions are started while the Program object has running threads |
nothing Qore::Program::parseCommit | ( | ) |
Commits and pending code processed with Program::parsePending() to the Program object after resolving all outstanding references in the pending code.
An exception in this method causes all pending code to be rolled back immediately.
PROGRAM-PARSE-ERROR | this exception is thrown if any parse actions are started while the Program object has running threads |
*hash<ExceptionInfo> Qore::Program::parseCommit | ( | int | warning_mask | ) |
Commits and pending code processed with Program::parsePending() to the Program object after resolving all outstanding references in the pending code.
An exception in this method causes all pending code to be rolled back immediately.
PROGRAM-PARSE-ERROR | this exception is thrown if any parse actions are started while the Program object has running threads |
*hash<ExceptionInfo> Qore::Program::parsePending | ( | string | code, |
string | label, | ||
*softint | warning_mask, | ||
*string | source, | ||
*softint | offset, | ||
softbool | format_label = True |
||
) |
Parses the text passed to pending lists in the Program object; does not resolve all references or commit the code to the Program object.
References are resolved in the Program::parseCommit() method.
Program::parseCommit() must be called to resolve all references and commit the code to the Program object; until Program::parseCommit() is called, none of the code parsed by this method will be available for execution in the Program object.
If an exception occurs in this method, all pending code is backed out, not just code parsed by this method.
code | The code to parse into the Program object |
label | The label for the code; this label will be given if any parse or run-time errors are raised for the code given |
warning_mask | An optional warning mask; see Warning Constants for values to combine by binary-or; if this argument is 0 or not given then no warnings will be checked or issued and the return value will always be NOTHING |
source | An optional source file name for the code being parsed; this is useful if sections of a file are parsed |
offset | An optional line offset for use with the source parameter; this gives the line offset in the file to the code being parsed |
format_label | obsolete / ignored since Qore 0.9 |
PROGRAM-PARSE-ERROR | this exception is thrown if any parse actions are started while the Program object has running threads |
nothing Qore::Program::parseRollback | ( | ) |
Removes all partially or fully-parsed code from the object along with other builtin objects; a Program object is not usable after calling this method; do not use this method but instead destroy the Program object.
PROGRAM-PARSE-ERROR | this exception is thrown if any parse actions are started while the Program object has running threads |
nothing Qore::Program::replaceParseOptions | ( | softint | opt | ) |
Replaces the parse options for the Program object.
An OPTION-ERROR
exception is thrown if the calling Program object does not have PO_NO_CHILD_PO_RESTRICTIONS set.
opt | A single parse option or binary-or'ed combination of parse options to unset in the parse option mask for the object |
OPTION-ERROR | The calling Program does not have the PO_NO_CHILD_PO_RESTRICTIONS option set, and therefore cannot call Program::replaceParseOptions() |
auto Qore::Program::run | ( | ) |
Runs the program and optionally returns a value if the top-level code exits with a return statement.
nothing Qore::Program::setGlobalVarValue | ( | string | name, |
auto | value | ||
) |
set the value of a global variable
name | the name of the variable |
value | the value to assign |
UNKNOWN-VARIABLE | the variable is not a global variable |
nothing Qore::Program::setParseOptions | ( | softint | opt = PO_DEFAULT | ) |
Sets parse options in the parse option mask for the Program object.
An OPTIONS-LOCKED
exception is thrown if parse options have been locked (for example with Program::lockOptions())
opt | A single parse option or binary-or'ed combination of parse options to set in the parse option mask for the object; the given argument will be combined with binary or with the existing parse option mask |
OPTIONS-LOCKED | Parse options have been locked and cannot be changed |
PROGRAM-OPTION-ERROR | invalid parse options used |
nothing Qore::Program::setScriptPath | ( | *string | path | ) |
Sets (or clears) the script path (directory and filename) for the object.
path | The path (directory and filename) for the current script; if the directory component is missing, then the current directory is assumed |
bool Qore::Program::setThreadInit | ( | *code | init | ) |
Sets a call reference or closure to run every time a new thread is started.
This code can be used to initialize global thread-local variables, for example.
init | a call reference or closure to run every time a new thread is started or NOTHING to clear any thread initialization code |
nothing Qore::Program::setTimeZone | ( | TimeZone | zone | ) |
Sets the default local time zone for the object.
nothing Qore::Program::setTimeZoneRegion | ( | string | region | ) |
Sets the default local time zone for the object from a path to a zoneinfo time zone region file.
If there are errors opening, reading, or parsing the file (or the Windows registry entry, depending on the platform), an exception is thrown
region | The path to the zoneinfo file for the time zone region to set as the local time zone for the Program object |
TZINFO-ERROR | Unable to read zoneinfo file; invalid file magic; error parsing zoneinfo file, etc |
nothing Qore::Program::setTimeZoneUTCOffset | ( | softint | seconds_east | ) |
Sets the default time zone for the Program object based on the number of seconds east of UTC; for zones west of UTC, use negative numbers.
Time zones set with this method cannot have any daylight savings time information; to set a zone with daylight savings time information, use Program::setTimeZoneRegion() instead
seconds_east | The number of seconds east of UTC; for zones west of UTC, use negative numbers |
nothing Qore::Program::undefine | ( | string | def | ) |
Unsets a parse define for the current Program.
def | The name of the define to undefine; if the given define is not defined anyway, the operation is ignored |