Skip to main content

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

JLua-basic-DrSamse-0.2.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

JLua_basic_DrSamse-0.2.0-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page