Giter Club home page Giter Club logo

pygame-80's People

Contributors

kyuchumimo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

aliozanyerli

pygame-80's Issues

Why is it not possible to run the source code of the TIC() function?

Problem (The module may look like this):

#CODE0

def TIC():
    #CODE1

#CODE2

Objective:

  • 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.