Git Product home page Git Product logo

lperkins2-programs's Introduction

#####NAME python - execute .pyc or .pyo file using the python.lua VM

#####SYNOPSIS python <file.pyc> [args ...]

#####DESCRIPTION python executes marshalled python code using a state machine It is also possible to require('python/python') and then call execfile('something.pyc') The return from execfile is the return value from the marshalled code object (usually None), and the global frame for the file. The variables defined in the python code can be retrieved from frame.locals.

######DATA TYPES python.lua implements several data types which have analogues in lua, and uses some lua types directly. Python data types are implemented as tables.

Numbers in python are just lua numbers

String literals and strings returned from lua are lua strings.
Python strings can be created via str(o), and support most of the usual python
str operations (find, split, ...).  somestr.s is the underlying lua string.

list and dict literals create lua tables, python lists and dicts are creatable
by specifically invoking list() and dict().  Additionally, lists can be created
from lua tables via list.staticFromTable(t), and converted back to tables via 
l.toTable()

Dictionaries are still alpha, so it is recommended to just use lua tables.

Classes are supported, but must explicitly subclass something (object, type, another class ...)
Additionally, they must define a __repr__ method which returns either a string or
str.  __repr__ is used both to represent the class and instances of the class

Python functions can be called from lua, and lua functions can be called from python
python does not use : to specify binding the containing object to self in a function
body, so the python vm tries to determine when it is appropriate to do so.  In some
cases with lua functions, it cannot, so the self argument must be specified
explicitly.
    f=filesystem.open(path)
    txt=f.read(f,length)
When a lua function returns nil, it is automatically converted to None.  nil
should never appear in the python vm, since it cannot be put on the python stack.
This means failed attribute lookups raise an AttributeError or similar.  Use
hasattr(obj,attr) to determine if the attribute exists.

######IMPORTS lua libraries may be require()d, python libraries may be import ed The python path defaults to /usr/lib/python2 additional libraries may be specified via set PYTHONPATH=loc1:loc2 Note that python libraries must end in .pyc (.pyo files are ignored) lua libraries persist across runs (package.loaded) python libraries are discarded when then vm shuts down. Relative imports are unreliable, so use absolute imports

######THREADING The python vm does not support threading between python functions. If the coroutine holding the python vm yields, when it resumes, the python stack must be in exactly the same state or unpredictable errors result.

######EXCEPTION HANDLING try/except is not supported. For pure lua functions, use pcall. For python functions use dotry(EXECUTE, frame), where frame=Frame.create(Frame, code)

######PERFORMANCE Not as bad as one might expect, but function calls are very expensive. Also, unmarshalling modules requires a lot of memory, so anything large will require a tier 3 computer with at least 1 tier 3 memory card.

Not all opcodes are implemented, specifically, func(*args, **kw) and its variants is not supported (due to the documentation for it being junk). Instead, use apply(func,args)

Also, returning multiple values from lua is not reiably supported. The function callAndPack(func,arg1,...) will return a lua table containing all the return values.

Pay attention to your data types, remember, python lists index from 0, lua tables index from 1.

Since python.lua lacks a lexile parser, the .pyc files must be generated by some remote computer. In /usr/lib/python2, there's a fuse module which can be set up by a server admin and a CC disk (or OC if caching is disabled) (linux/posix only). More generally, an internet card + wget lets you copy .pyc files to the computer; compile them on the host via python -m compileall . In the near future, I'll set up a publically accessible compillation server, and write a script to send the local python files to it automatically.

lperkins2-programs's People

Contributors

perkinslr avatar vexatos avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

programivan

lperkins2-programs's Issues

tonumber(str(s))==nil

lua does not have a __tonumber metamethod, so short of replacing the tonumber function, this is not fixable.

Instead, a helper function (float) should be added which is aware of python types.

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.