A Package for Json-like Lua usement in python
Project description
JLua - Basic - Package
Description
This package enables Json-like Lua usement for Python3.
It enables converting python Objects into Lua.
For evaluation, the package uses its defined requirement 'lupa'.
Functions
Help Functions
Sumstring(table : list) -> str
Connects all the strings in the list to a single string, optimal for the output of JLua.GetLuaString()
Params:
- table : list :: A string list like generated by readlines() or GetLuaString()
from JLua import SumString, GetLuaString
print(GetLuaString({ "test" : [10, 20, 30], "var" : "string" })
# Output >>> ['{\n', ' test = { 10, 20, 30, },\n', ' var = "string",\n', '}'])
print(SumString(GetLuaString({ "nice" : [10, 20, 30], "var" : "string" })))
""" Output:
{
test = { 10, 20, 30, },
var = "string",
}
"""
Python to Lua
GetLuaString( obj ) -> list
The main converting function. Can convert the basic types, if the type(obj) is not one of the basic python types, the function tries to get the repr of the obj
( In future times there will be a universal Lua-Repr funktion to easily convert user-defined classes to Lua )
Params:
- obj :: Can be any object, but stick to the convertion rules
from JLua import GetLuaString, SumString
objInt = 1
objString = "objString"
objList = [ objInt, objString ]
objDict = { "objInt" : objInt, "objString" : objString, "objList" : objList }
print(SumString(GetLuaString(objInt)))
# Output >>> 1
print(SumString(GetLuaString(objString)))
# Output >>> "objString"
print(SumString(GetLuaString(objList)))
# Output >>> { 1, "objString", }
print(SumString(GetLuaString(objDict)))
""" Output
{
objInt = 1,
objString = "objString",
objList = { 1, "objString", },
}
"""
Lua to Python
DecodeToDict( luaString : str = "", useDecoded : bool = False, decoded = None ) -> dict
Decode a Lua-Table to a python-Dict
Params:
- luastring : str = "" :: The LuaCode to eval to a Lua-Table and edit the return dictionary
- useDecoded : bool = False :: True if a pre-evaluated Lua-table
- decoded = None :: The already decoded table, mostly used for the algroythm itself
-- ./example.lua
{
objInt = 10,
objString = "string",
objList = { 10, "string" },
}
# ./main.py
from JLua import DecodeToDict
print(DecodeToDict(open("example.py").read()))
# Output >>> {'objList': {0: 10, 1: 'string'}, 'objInt': 10, 'objString': 'string'} or in other order
DecodeToClass( luaString : str, configClass = JLua.LuaCreatedClass(), useDecoded : bool = False, decoded = None) -> JLua.LuaCreatedClass ! WIP !
Decode a Lua-Table to a python-Class
AutoClass: JLua.LuaCreatedClass
Params:
- luastring : str = "" :: The LuaCode to eval to a Lua-Table and edit the return dictionary
- configClass = JLua.LuaCreatedClass() :: The class to set the in the table given args to
- useDecoded : bool = False :: True if a pre-evaluated Lua-table should be used
- decoded = None :: The already decoded table, mostly used for the algroythm itself
-- ./example.lua
{
objInt = 10,
objString = "string",
objList = { "string" : 10 },
}
# ./main.py
from JLua import DecodeToClass
print( DecodeToClass(open("example.py").read()).objInt, DecodeToClass(open("example.py").read()).objString )
# Output >>> 10 string
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file JLua-basic-DrSamse-0.2.0.tar.gz.
File metadata
- Download URL: JLua-basic-DrSamse-0.2.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbd9855e5c5071708f9335ab22f1e3fd57eb5270d94b5adbf2204212f5d04296
|
|
| MD5 |
4802009273a462c26f9b7fcbc79cf67b
|
|
| BLAKE2b-256 |
9f29d5eb6f22483ee1a248f1ece683b27de105a79892fa6fa4de8fa72fe40c6c
|
File details
Details for the file JLua_basic_DrSamse-0.2.0-py3-none-any.whl.
File metadata
- Download URL: JLua_basic_DrSamse-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7838ecdd160624ea1102e1fad7bb085b06c8a8eca6404b5630aa51fa410575c3
|
|
| MD5 |
26e22c7f7004e824c867deeeb2bdabe5
|
|
| BLAKE2b-256 |
fc4112e7df96cce05919ccfc03080ce897ad4978c9180cb48dfa02ee7e4b3a90
|