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())
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()
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 = "" (0x0022) %22 0x22 034 "",\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 = "" (0x0022) %22 0x22 034 "",\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
, 3.1415926535897932384626433832795028841971693993751058209749445923 , 1066 ,"rosebud" }} ''') d = parser.dumpDict() print d parser.loadDict(d) parser["root"][96] = "Hello World" parser.update({"root":1}) # parser["root"][4] = "Hello World" parser.dumpLuaTable("output2.lua") # print "------------------" parser.loadLuaTable("output2.lua") sd2 = parser.dumpDict() print "--------------------------" print sd2 # print "-------------" # print parser.dumpLuaTable("table_test.lua") # # print PythonStrToStruct('''{ # # "array": [65, 23, 5], # # "dict": {
from PyLuaTblParser import * lua_table_str = '{array = {65,23,5,},["dict"] = {mixed = {43,54.33,false,9,string = "value",},array = {3,6,4,};string = "value",},}' Parser1 = PyLuaTblParser() Parser1.load(lua_table_str) parsed_lua_table1 = Parser1.dumpDict() print parsed_lua_table1 Parser2 = PyLuaTblParser() Parser2.loadDict(parsed_lua_table1) parsed_lua_table2 = Parser2.dumpDict() print parsed_lua_table2 Parser1.dumpLuaTable("lua_table.lua") Parser2.dumpLuaTable("lua_table.lua") Parser1.loadLuaTable("lua_table.lua") parsed_lua_table3 = Parser1.dumpDict() print parsed_lua_table3 Parser3 = PyLuaTblParser() Parser3.loadLuaTable("rawluatable.lua") Parser3.dumpLuaTable('testcase.lua') Parser3.loadLuaTable('testcase.lua') Parser3.dumpLuaTable('testcase.lua')
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