示例#1
0
def main():
	while True:
		try:
			luatext = raw_input('lua_filename>')
		except EOFError:
			break
		if not luatext:
			continue
		a1 = PyLuaTblParser()
		print(luatext)
		a1.loadLuaTable(luatext)
		print(a1.dump())
		try:
			wtext = raw_input('wirte_to_filename>')
		except EOFError:
			break
		if not wtext:
			continue
		a1.dumpLuaTable(wtext)

		try:
			dictext = raw_input('dict_filename>')
		except EOFError:
			break
		if not dictext:
			continue
		a2 = PyLuaTblParser()
		with open(dictext, 'r') as file:
			d = file.read()
			dic = ast.literal_eval(d)
		a2.loadDict(dic)
		print(a2.dumpDict())
		print(a2.dump())
示例#2
0
def test4():
    print '.................... Test4'
    f = open('test4.txt', 'r')
    lines = f.readlines()
    p = PyLuaTblParser()
    count = 1
    for line in lines:
        print '----------- line ' + str(count) + ' :'
        count += 1
        if len(line) > 0 and line[0] == '#' or line.isspace():
            print '... omitted'
            continue
        p.load(line)
        print p.dump()
    f.close()
示例#3
0
def main():
    while True:
        try:
            text = raw_input('lua>')
        except EOFError:
            break
        if not text:
            continue
        a1 = PyLuaTblParser()
        a1.load(text)
        print(a1.dump())
示例#4
0
def test3():
    print '.................... Test3 loadDict and dumpDict'
    info = {'name': 'William', 'age': 24, 'gender': 'Male', 'description': ''}
    print info
    p = PyLuaTblParser()
    p.loadDict(info)
    print p.dump()
    info['description'] = 'blabla...'
    print info
    print p.dump()

    dct = p.dumpDict()
    dct['age'] = 24.5
    print dct
    print p.dump()
示例#5
0
                    3,
                    [45] = 11    --[[fdsaf--]],
                    [''] = '',
                    ''
                }
            }
        }
    ,,,}'''

    test_str = '''{\r\nroot = {\r\n\t"Test Pattern String",\r\n\t-- {"object with 1 member" = {"array with 1 element",},},\r\n\t{["object with 1 member"] = {"array with 1 element",},},\r\n\t{},\r\n\t[99] = -42,\r\n\t[98] = {{}},\r\n\t[97] = {{},{}},\r\n\t[96] = {{}, 1, 2, nil},\r\n\t[95] = {1, 2, {["1"] = 1}},\r\n\t[94] = { {["1"]=1, ["2"]=2}, {1, ["2"]=2}, ["3"] = 3 },\r\n\ttrue,\r\n\tfalse,\r\n\tnil,\r\n\t{\r\n\t\t["integer"]= 1234567890,\r\n\t\treal=-9876.543210,\r\n\t\te= 0.123456789e-12,\r\n\t\tE= 1.234567890E+34,\r\n\t\tzero = 0,\r\n\t\tone = 1,\r\n\t\tspace = " ",\r\n\t\tquote = "\\"",\r\n\t\tbackslash = "\\\\",\r\n\t\tcontrols = "\\b\\f\\n\\r\\t",\r\n\t\tslash = "/ & \\\\",\r\n\t\talpha= "abcdefghijklmnopqrstuvwyz",\r\n\t\tALPHA = "ABCDEFGHIJKLMNOPQRSTUVWYZ",\r\n\t\tdigit = "0123456789",\r\n\t\tspecial = "`1~!@#$%^&*()_+-={\':[,]}|;.</>?",\r\n\t\thex = "0x01230x45670x89AB0xCDEF0xabcd0xef4A",\r\n\t\t["true"] = true,\r\n\t\t["false"] = false,\r\n\t\t["nil"] = nil,\r\n\t\tarray = {nil, nil,},\r\n\t\tobject = {  },\r\n\t\taddress = "50 St. James Street",\r\n\t\turl = "http://www.JSON.org/",\r\n\t\tcomment = "// /* <!-- --",\r\n\t\t["# -- --> */"] = " ",\r\n\t\t[" s p a c e d " ] = {1,2 , 3\r\n\r\n\t\t\t,\r\n\r\n\t\t\t4 , 5        ,          6           ,7        },\r\n\t\t--[[[][][]  Test multi-line comments\r\n\t\t\tcompact = {1,2,3,4,5,6,7},\r\n\t- -[luatext = "{\\"object with 1 member\\" = {\\"array with 1 element\\"}}",\r\n\t\tquotes = "&#34; (0x0022) %22 0x22 034 &#x22;",\r\n\t\t["\\\\\\"\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?"]\r\n\t\t= "A key can be any string"]]\r\n\t--         ]]\r\n\t\tcompact = {1,2,3,4,5,6,7},\r\n\t\tluatext = "{\\"object with 1 member\\" = {\\"array with 1 element\\"}}",\r\n\t\tquotes = "&#34; (0x0022) %22 0x22 034 &#x22;",\r\n\t\t["\\\\\\"\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?"]\r\n\t\t= "A key can be any string"\r\n\t},\r\n\t0.5 ,31415926535897932384626433832795028841971693993751058209749445923.\r\n\t,\r\n\t3.1415926535897932384626433832795028841971693993751058209749445923\r\n\t,\r\n\r\n\t1066\r\n\r\n\r\n\t,"rosebud"\r\n\r\n}}
    '''

    a1 = PyLuaTblParser()
    a2 = PyLuaTblParser()
    a3 = PyLuaTblParser()

    a1.load(test_str)
    print a1.dump()
    d1 = a1.dumpDict()

    a2.loadDict(d1)
    a2.dumpLuaTable('output.txt')
    a3.loadLuaTable('output.txt')

    d3 = a3.dumpDict()

    print d1 == d3
    print '\n'
    print d1
    print '\n'
    print d3
示例#6
0
from PyLuaTblParser import *
a1 = PyLuaTblParser()
a2 = PyLuaTblParser()
a3 = PyLuaTblParser()

test_str = '{array = {65,23,5},dict = {mixed = {43,54.33,false,9,string = "value",},array = {3,6,4,},string = "value",},}'
a1.load(test_str)
d1 = a1.dump()
print d1
d1 = a1.dumpDict()
print d1

a2.loadDict(d1)

d2 = a2.dump()
print d2
file_path = "lua_table_test.lua"

#a2.dumpLuaTable(file_path)
a3.loadLuaTable(file_path)
d3 = a3.dump()
print d3
d3 = a3.dumpDict()
print d3
a3.loadDict(d3)
d3 = a3.dump()
print d3
示例#7
0
def test2():
    print '.................... Test2 loadLuaTable and dumpLuaTable'
    p = PyLuaTblParser()
    p.loadLuaTable('test2-load.txt')
    print p.dump()
    p.dumpLuaTable('test2-dump.txt')
示例#8
0
def test1():
    print '.................... Test1 load and dump :'

    p = PyLuaTblParser()

    s0 = '{[\'232\'] = {}}'
    print '... load s0'
    p.load(s0)
    print '... dump'
    print p.dump()

    s1 = '{[\'array\'] = {65, 23, 5,}}'
    print '... load s1'
    p.load(s1)
    print '... dump'
    print p.dump()

    s2 = '{"Sunday", "Monday", "Tuesday", \'Wednesday\', "Thursday", "Friday", "Saturday"}'
    print '... load s2'
    p.load(s2)
    print '... dump'
    print p.dump()
    print p[1]
    # print p[0]

    s3 = '{x=0,y=1,[3]=2}'
    print '... load s3'
    p.load(s3)
    print '... dump'
    print p.dump()
    print p[3]

    s4 = '{array = {65,23,5,},dict = {mixed = {43,54.33,false,9,string = "value",},array = {3,6,4,},string = "value",},}'
    print '... load s4'
    p.load(s4)
    print '... dump'
    print p.dump()

    s5 = '{color="blue", thickness=2, npoints=4,\
                 {x=0,   y=0},\
                 {x=-10, y=0},\
                 {x=-10, y=1},\
                 {x=0,   y=1}\
          }'

    print '... load s5'
    p.load(s5)
    print '... dump'
    print p.dump()

    p = PyLuaTblParser()
    s6 = '{["x"]=0, ["y"]=0}'
    print '... load s6'
    p.load(s6)
    print '... dump'
    print p.dump()

    s7 = '{x=10, y=45; "one", "two", "three"}'
    print '... load s7'
    p.load(s7)
    print '... dump'
    print p.dump()

    # Test tables with 'nil'
    s8 = '{x=nil, y = 0, z=nil, nil}'
    print '... load s8'
    p.load(s8)
    print '... dump'
    print p.dump()

    # Test tables with 'nil'
    s8 = '{nil, 0, nil, 1}'
    print '... load s8'
    p.load(s8)
    print '... dump'
    print p.dump()
    print p[1], p[2], p[3], p[4]

    s9 = '{["x"]="{", ["y"]="}"}'
    print '... load s9'
    p.load(s9)
    print '... dump'
    print p.dump()