RecompExternalPython for N64Recompiled 2.0.0
Loading...
Searching...
No Matches

Macros

#define REPY_FN_EXEC(code_handle)
 Executes Python code object within the current inline execution scope.
#define REPY_FN_EXEC_CSTR(code_str)
 Executes Python code string string within the current inline execution scope.
#define REPY_FN_EXEC_CACHE(identifier, code_str)
 Executes a Python code string string within the current inline execution scope, compiling it the first time it's run and caching the bytecode for subsequent uses.

Detailed Description

Parse and execute Python code strings within this scope. An extremely flexable way of interweaving mod code and Python code.

Macro Definition Documentation

◆ REPY_FN_EXEC

#define REPY_FN_EXEC ( code_handle)
Value:
REPY_bool REPY_Exec(REPY_Handle code, REPY_Handle global_scope_nullable, REPY_Handle local_scope_nullable)
Execute Python code statements from a REPY_Handle. Optionally provide dict objects to serve as a scop...
#define REPY_FN_GLOBAL_SCOPE
The variable name for inline execution global scopes.
Definition repy_api.h:750
#define REPY_FN_LOCAL_SCOPE
The variable name for inline execution local scopes.
Definition repy_api.h:756

Executes Python code object within the current inline execution scope.

The code to execute should already be a Python object. A precompiled bytecode object is recommended for performance reasons, but a Python str object will also work.

Parameters
code_handleThe Python code to execute. Should be a REPY_Handle to a valid code object.
Returns
1 if execution was successful, 0 if there was an error.

◆ REPY_FN_EXEC_CACHE

#define REPY_FN_EXEC_CACHE ( identifier,
code_str )
Value:
REPY_INLINE_COMPILE_CACHE_BLOCK("REPY_FN_EXEC_CACHE", identifier, REPY_CODE_EXEC, code_str) \
REPY_bool identifier ## _success = REPY_FN_EXEC(identifier)
#define REPY_FN_EXEC(code_handle)
Executes Python code object within the current inline execution scope.
Definition repy_api.h:914
#define REPY_INLINE_COMPILE_CACHE_BLOCK(category, bytecode_identifier, code_mode, code_str)
Inside a function, construct a code block that compiles to bytecode a Python code string the first ti...
Definition repy_api.h:619
_Bool REPY_bool
A boolean type compatible with libultra's bool type.
Definition repy_api.h:133
@ REPY_CODE_EXEC
Equivalent to exec.
Definition repy_api.h:145

Executes a Python code string string within the current inline execution scope, compiling it the first time it's run and caching the bytecode for subsequent uses.

This is the recommended method of inlining executable blocks of Python code inside of functions. The performance difference made by not having to recompile the code strings into bytecode for every run is substantial.

Because this macro expands to a block of code, rather than a single funtion call, the success of the execution is stored in a variable named [identifier]_success. This variable will be 1 if execution was successful, 0 if there was an error.

Parameters
identifierThe name for a static variable that will hold the Python bytecode handle once created.
code_strThe Python code to execute. Should be a NULL-terminated C-string such as a string literal. This code string will only be parsed and compiled once.

◆ REPY_FN_EXEC_CSTR

#define REPY_FN_EXEC_CSTR ( code_str)
Value:
REPY_bool REPY_ExecCStr(const char *code, REPY_Handle global_scope_nullable, REPY_Handle local_scope_nullable)
Execute Python code from a NULL-terminated C string. Optionally provide dict objects to serve as a sc...

Executes Python code string string within the current inline execution scope.

Not generally recommended, since this will require recompiling the Python code string every time it's run. It is technically faster than REPY_FN_EXEC_CACHE for code that is only used once (since one fewer handle lookup is involved), but the difference is so marginal that it really doesn't matter.

Parameters
code_strThe Python code to execute. Should be a NULL-terminated C-string such as a string literal or a const char*.
Returns
1 if execution was successful, 0 if there was an error.