Jump to content


table serializaton


    2 replies to this topic

    #1 sebyg666


      Advanced Member

    • Members
    • PipPipPip
    • 32 posts

      Posted 10 August 2016 - 07:44 AM

      ok i've been scratching my head, look all over the web and cannot find a propper answer.

      i want to serialise, or should i say save the contents of a table to a file for later reading, in the most efficient way. essentially exactly how the resources files look, and are included in addons. its quiet important its efficient as on load of the addon the addon will turn the file back into a table. the table could be big as the maximum contents of all the characters storage. i may need to nest (i think is the correct term) some tables within tables too. for example:


      table = {id = xxxxx, augemnts = {[1] = xxxxxx, [2] = xxxxxxx, [3] = xxxxxx}, name = xxxxx, delay = xxxxx} etc


      i basicly want to create a resource table from the 'item_description' resources and the augments of each individual item in all inventories of a character.


      thanks for any help anyone can supply, my current method takes too long and makes the player red dot so long you actually DC in game.

      #2 trv


        Advanced Member

      • Members
      • PipPipPip
      • 34 posts

        Posted 11 August 2016 - 10:53 AM

        This is quick and dirty, but it takes little to no effort:

        require 'logger'
        require 'tables'
        files = require 'files'
        blah = files.new('some path string')
        -- to write
        blah:write('return ' .. T(your_table):tovstring())
        -- to load
        your_table = loadfile('some path string')()

        I don't know if it would handle a self-referencing table.

        #3 sebyg666


          Advanced Member

        • Members
        • PipPipPip
        • 32 posts

          Posted 11 August 2016 - 02:55 PM

          lol at the structure, but it works great, like you say its dirty lol, i did actually figure the answer before your post, but this takes less work ^^

          thanks a bunch for the reply.

          Also tagged with one or more of these keywords: lua

          1 user(s) are reading this topic

          0 members, 1 guests, 0 anonymous users