kyuchumimo / pygame-80 Goto Github PK
View Code? Open in Web Editor NEWA set of functions from TIC-80 tiny computer 0.90.1723 platform ported to Pygame 2
License: MIT License
A set of functions from TIC-80 tiny computer 0.90.1723 platform ported to Pygame 2
License: MIT License
Problem (The module may look like this):
#CODE0
def TIC():
#CODE1
#CODE2
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:
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.