You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To take the source code of the TIC() function (#CODE1) from a module and execute it with exec().
exec(#CODE1)
Tested ideas, but with failures.
Idea 1:
Import only the TIC() function using from __ import __, so as to read its code with inspect.getsource() and execute it with exec()
Failure: If the code contains an instruction outside of the TIC() function that calls a TIC-80 function, an error of type NameError: name '__' is not defined ocurrs, in addition to the execution of standard Python function instructions such as print() and variable assignment that would only occur locally.
Idea 2:
Read the .py file and execute all your code with exec(), to indirectly "import" the TIC() function, plus the user variables and functions globally, then read the code with inspect.getsource() and execute it with exec().
Failure: OSError: could not get source code.
Idea 3:
Import only the TIC() function without other instructions outside the TIC() function being executed (print(), TIC-80 functions, variable assignment) using source code, then read the code with inspect.getsource() and execute it with exec().
Failure: OSError: source code not available
Source code:
import ast
import types
with open("__.py") as f:
p = ast.parse(f.read())
for node in p.body[:]:
if not isinstance(node, ast.FunctionDef):
p.body.remove(node)
module = types.ModuleType("mod")
code = compile(p, "mod.py", 'exec')
sys.modules["mod"] = module
exec(code, module.__dict__)
from mod import TIC
Idea 4:
Read the .py file and extract the TIC() function using text processing, then run your code with exec().
Notes: This has not been tested
Idea 5:
Execute the TIC() function globally, so that you can access the TIC-80 functions and assign global variables without any problems.
Failure: Requires modifying the original code using the global keyword for each of the functions and variables that the module tries to use or assign as far as I know.
Notes: This has not been tested
Idea 6:
Import the module globally, so that no assignment errors or TIC-80 function calls occur in the initialization process.
Notes: This has not been tested.
Idea 7:
Import the module and use try except in case of allocation errors or TIC-80 function calls in the initialization process. in the initialization process.
Failure: This does not work because with the first error that pops up, the import process is interrupted.
Idea 8 (Discarded):
Inject code to the TIC() function by code or by text processing so that it can be executed correctly
using decoardors.
Failure: This approach does not work, since being a function, the code runs locally and errors occur in allocating or using TIC-80 functions.
Idea 9 (Almost functional):
Use setattr and make all TIC-80 functions globally accessible at the level of standard functions (builtins).
Failure: There are confusions with standard Python functions (cls, exit, map, print) and TIC-80 functions.
The text was updated successfully, but these errors were encountered:
Problem (The module may look like this):
Objective:
exec(#CODE1)
Tested ideas, but with failures.
Idea 1:
Import only the TIC() function using from __ import __, so as to read its code with inspect.getsource() and execute it with exec()
Failure: If the code contains an instruction outside of the TIC() function that calls a TIC-80 function, an error of type NameError: name '__' is not defined ocurrs, in addition to the execution of standard Python function instructions such as print() and variable assignment that would only occur locally.
Idea 2:
Read the .py file and execute all your code with exec(), to indirectly "import" the TIC() function, plus the user variables and functions globally, then read the code with inspect.getsource() and execute it with exec().
Failure: OSError: could not get source code.
Idea 3:
Import only the TIC() function without other instructions outside the TIC() function being executed (print(), TIC-80 functions, variable assignment) using source code, then read the code with inspect.getsource() and execute it with exec().
Failure: OSError: source code not available
Source code:
Idea 4:
Read the .py file and extract the TIC() function using text processing, then run your code with exec().
Notes: This has not been tested
Idea 5:
Execute the TIC() function globally, so that you can access the TIC-80 functions and assign global variables without any problems.
Failure: Requires modifying the original code using the global keyword for each of the functions and variables that the module tries to use or assign as far as I know.
Notes: This has not been tested
Idea 6:
Import the module globally, so that no assignment errors or TIC-80 function calls occur in the initialization process.
Notes: This has not been tested.
Idea 7:
Import the module and use try except in case of allocation errors or TIC-80 function calls in the initialization process. in the initialization process.
Failure: This does not work because with the first error that pops up, the import process is interrupted.
Idea 8 (Discarded):
Inject code to the TIC() function by code or by text processing so that it can be executed correctly
using decoardors.
Failure: This approach does not work, since being a function, the code runs locally and errors occur in allocating or using TIC-80 functions.
Idea 9 (Almost functional):
Use setattr and make all TIC-80 functions globally accessible at the level of standard functions (builtins).
Failure: There are confusions with standard Python functions (cls, exit, map, print) and TIC-80 functions.
The text was updated successfully, but these errors were encountered: