Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Create, append multidimentional array table lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Jun 25, 2020 7:50 pm    Post subject: Create, append multidimentional array table lua Reply with quote

Say I have a table.

Code:
mytable = {}
data1 = 'corroder'
data2 = 'dumb'
data3 = 1000


I can append an item to mytable like this:

Code:
table.insert(mytable, data1)

-- or

function addTblItem(...)
  for i = 1, select('#',...) do
   mytable[#mytable+1] = select(i,...)
  end
end

addTblItem(data1, data2, data3)
for i = 1, #mytable do print(mytable[i]) end


I got tree items in tree line rows on mytable.

But, what I want is a multidimensional array table, example:

Code:
mytable = {
{ data1 = 'corroder',  data2 = 'dumb',  data3 = 1000},
{ data1 = 'someone',  data2 = 'something',  data3 = somenumber}
-- and so on
}


Questions:
1. How to create or append items to mytable with the table structure as I wanted above using Lua CE script?
2. How to check if an item is already exist on mytable by data1 and data2

I have search in google for some references or examples but cant find a matched case.

EDIT : SELF ANSWER Q1:

I can do it like this:

Code:
mytable = {}
data1 = 'corroder'
data2 = 'dumb'
data3 = 1000

mytable = { data1 = data1, data2 = data2, data3 = data3}
print(mytable.data1, mytable.data2, mytable.data3)

data1 = 'dtrump'
data2 = 'politic'
data3 = 10000

mytable[2] = { data1 = data1, data2 = data2, data3 = data3}
print(mytable[2].data1, mytable[2].data2, mytable[2].data3)


Just need turn to append items to the table into a function.
Or (Q3) how use table.insert to append item on table?

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
blankTM
Cheater
Reputation: 1

Joined: 03 May 2020
Posts: 49

PostPosted: Thu Jun 25, 2020 8:49 pm    Post subject: Re: Create, append multidimentional array table lua Reply with quote

HashMap:
Code:

---------------------------------
-- Author: Reyn
-- Date: 2016-07-01
-- Comment: HashMap
---------------------------------

function table.keyAsValue(...)
    local arr = {...}
    local ret = {}
    for _,v in ipairs(arr) do
        ret[v] = v
    end
    return ret
end

function table.len(tbl)
    local count = 0
    for k, v in pairs(tbl) do
        count = count + 1
    end
    return count
end

function table.print(tbl)
    local format = string.format
    for k,v in pairs(tbl) do
        print(format('[%s] => ', k), v)
    end
end

DATA_TYPE = table.keyAsValue('boolean', 'number', 'string', 'function', 'table', 'thread', 'nil')

function checkType(v, type)
    return v == DATA_TYPE[type]
end

local function checkHashType(tp)
    if not (tp == 'Mixed' or DATA_TYPE[tp]) then
        tp = 'Mixed'
    end
    return tp
end

function Map(ktype, vtype)
    local new_map = {}
    local __map__ = {}

    local __methods__ = {}
    local __key_type__, __value_type__ = checkHashType(ktype), checkHashType(vtype)
    function __methods__:typeOf()
        return string.format('HashMap<%s, %s>',__key_type__,__value_type__)
    end
    function __methods__:len()
        return table.len(__map__)
    end
    function __methods__:set(k, v)
        if (__key_type__ == 'Mixed' or type(k) == __key_type__)
        and (__value_type__ == 'Mixed' or type(v) == __value_type__) then
            __map__[k] = v
        end
    end
    function __methods__:unset(k)
        __map__[k] = nil
    end
    function __methods__:print()
        table.print(__map__)
    end
    function __methods__:filterKey(tp)
        print('filter key type:',tp)
        for k,v in pairs(__map__) do
            if not checkType(type(k), tp) then
                __map__[k] = nil
            end
        end
    end
    function __methods__:filterValue(tp)
        print('filter value type:',tp)
        for k,v in pairs(__map__) do
            if not checkType(type(v), tp) then
                __map__[k] = nil
            end
        end
    end
    function __methods__:setKeyType(type)
        if not checkType(type, nil) then
            if __key_type__ == type then
                return
            end
            __key_type__ = type
            self:filterKey(type)
        end
    end
    function __methods__:setValueType(type)
        if not checkType(type, nil) then
            if __value_type__ == type then
                return
            end
            __value_type__ = type
            self:filterValue(type)
        end
    end
    function __methods__:filter(val)
        for k,v in pairs(__map__) do
            if v == val then
                __map[k] = nil
            end
        end
    end

    local mt = {
        __index = function(t, k)
            if __map__[k] then
                return __map__[k]
            end
            if __methods__[k] then
                return __methods__[k]
            end
        end,
        __newindex = function(t, k, v)
            if __methods__[k] then
                print('[warning] can not override native method.')
                return
            end
            __methods__:set(k, v)
        end
    }
    setmetatable(new_map, mt)

    return new_map
end


example:

Code:

require('map)
local map = Map()
map.len = function()
end                 -- would fail
print(map.len())    -- 0
map:set('b','b')
print(map.b)        -- b
print(map.len())    -- 1
map:unset('a')
map[1] = 'c'
print(map[1])       -- 1
map:print()         -- b=b, 1=c
print(string.rep('*', 20))
local map = Map('number', 'string')
map:set(1, 's')
map:set(2, 2)
map:set(3, function() return 3 end)
map:set('4', 4)
map:print()         -- [1]=s
map:setKeyType('string')
map:setValueType('number')
map:set('a', 22)
map:set(2, 'a')
map:set(1, 1)
map[3]   = 3
map.a    = 4
map[1] = false
map:print()         -- [a]=4

--or
map=decodeFunction([==[c-pmATW:dh6h1Q@,Z)%qqC@OaNR3FUDz$h)AP{O[E_j+:Mj$n,gi2(;.x)}quOoYNdqA0Wn)zQ]^DUe(.$PSxBGmFLsyzBHaQV+6I?!jx5S6.p$y[^h(UbF#/c-?K^vCS#r@(+Ff@wAOY}Q8R?A8%[PFKRYfWJ9%se!TJYHj8((nY%?ZT8JP?4DpSdaMQYdxC[J/Uw2PN$SUvW.H2=s9Ww4Ii(Z=B%n*;/I:$.)liMhDi]?HjX*Le2RmNpuHV:QlxhT[%B^ESVWbMzyd_%*@z}PtDQBhCY6O0$@5I5vC1_UBC(HO.*kJM0T#f22^1UCT1HY/NSZ{Dp;RPaRe]#kO8W.U[c2mGNe0j*A*=da?gft.n.O8xj2k.G$:?1@x5a{/p$ovAo:fyv{HC$rstWD,X;wdl6Nd,,dork/=j5-Aj9(2]:+1V^DbXIc*zfTQyAPj6[YG]7Nsn.NHnxBho@+S85.r8f2r[5:gkNWUXYVxEYEw!BOYT-*C9D7/A81Y{b3=XZrOQM@vwc1TTN^_fmGI4LNvs{8mP#S}iEy(vtXm@s3e)#c}zzRFQ2OxW{@m96#r?0:ZbPh6a,;^d-Do^E?LSIKzZ$Qb4YnAiuONnA;g1A]U4yymHzYOUb)8bFbet/mY]oM9%!iuXgiG7Scq3ICw0p@9i(.yUhSPx;[email protected]![toH[ev*(t@XRv-S?OX=LJjVTUSJERP[shTX+xk;]-w0[ENLgm}6D?^8GyRi}P}czIY{2StfJAMCW:I.SR(PW;](O]^(e@GLvLeo4*3nDV:4RKd@7fc:DwTRz4YpOWQVD{CJLjX#Ao5Mu%A[LCaq!-Syk_DDPO1iDWc,uoDeyyp)AG=HY=,VL+!i1(XAQmj?m!{_n)HiNOwEg_$c@OceaHvKTqc)=w-41YBZg+VieorL)rV0%::%[I6[TOsG%.kZub!B3)KgVF:,iOk6mHN)im?+;(WNYakVwu5a_R^zht[nq4zrvx#W:Enl6wZ21(C]3QSwCxT_Dd)@XC}=m_i{$?yMQuN7YUDf^lf)j/M0WMwSXul,#K3GIwwk4qYvnSU9Pc$D_;aob+toOezFYLA3BJJn=Kt-gNuY?_-1?oTWBXps)0,E8zhsabP_gGEIuVO}hy^,S]yj(x4jS^{:64f[9VJ/$3WgLB26}voD^#H,U=O,C#0yL+[9M4Cn45a;tk$$LEkA!F5BwPI8+EeA?1b[3ViCWk}R1tfv[!u_L_m,=owz-zg@cPqG6bu$h@0NgsJGJ(Joa6W-suC!^fah$?w*zdk/5Ey$+Qfs7d-e}6J*@PEZaz{2a{*7Oa1HEuJZM*Yn$zB5FTX97Ngt_zPm)2o#Efg)Ci8jeZiPu(yX2Yx(R[GQWqE}x4Gds{]x1PLyeR^gLPwxUvNGibN#*u0smQGGKgfp6DZ*prcL8)3:G^^f?lznm/.G5]==])()
local map = Map()
map:set(1,{1,2})
print(map[1][1])
map:set('a',{2,3})
print(map.a[2])
map[1] = {a='1',['b']=5,c=2}
map['hi'] = {a='1',['b']=5,c=2}
print(map['hi'].a)
print(map[1].a)
print(map[1].b)
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Jun 26, 2020 12:38 am    Post subject: Re: Create, append multidimentional array table lua Reply with quote

blankTM wrote:
HashMap: ...


Thanks for answer but that not really I am looking for.
I did on a simple way according to my project purpose

1. Create and append multi array table, example:

Code:
mytable = {}

data1 = 'corroder'
data2 = 'dumb'
data3 = 1000

mytable[1] = {data1 = data1, data2 = data2, data3 = data3}

data3 = 'dtrump'
data4 = 'politic'
data5 = 10000

mytable[#mytable+1] = {data1 = data3, data2 = data4, data3 = data4}

data6 = 'bjhonson'
data7 = 'republic'
data8 = 10

mytable[#mytable+1] = {data1 = data6, data2 = data7, data3 = data8}



2. Output my table, example

Code:
for i = 1, #mytable do
 print(mytable[i].data1,mytable[i].data2,mytable[i].data3)
end

for i = 1, #mytable do
 print(mytable[i].data1)
end




3. Check if elements exist on my table, example:

Code:
local key1 = 'corroder'
local key2 = 'dumb'

for i = 1, #mytable do
 if mytable[i].data1 == key1 and mytable[i].data2 == key2 then
    print('Data exist')
    break
 else
    print('Data not found')
 end
end


Or there is another way, using Lua metatable.


4. Here the complete code, to create multi array table, append items, save table to file, load table from file and print table contains.

Code:
do
local function exportstring( s )
 s = string.format( "%q",s )
 s = string.gsub( s,"\\\n","\\n" )
 s = string.gsub( s,"\r","\\r" )
 s = string.gsub( s,string.char(26),"\"..string.char(26)..\"" )
 return s
end

function table.save(  tbl,filename )
 local charS,charE = "   ","\n"
 local file,err
 if not filename then
 file =  { write = function( self,newstr ) self.str = self.str..newstr end, str = "" }
 charS,charE = "",""
 elseif filename == true or filename == 1 then
 charS,charE,file = "","",io.tmpfile()
 else
 file,err = io.open( filename, "w" )
 if err then return _,err end
 end
 local tables,lookup = { tbl },{ [tbl] = 1 }
 file:write( "return {"..charE )
 for idx,t in ipairs( tables ) do
 if filename and filename ~= true and filename ~= 1 then
 file:write( "-- Table: {"..idx.."}"..charE )
 end
 file:write( "{"..charE )
 local thandled = {}
 for i,v in ipairs( t ) do
 thandled[i] = true
 if type( v ) ~= "userdata" then
 if type( v ) == "table" then
 if not lookup[v] then
 table.insert( tables, v )
 lookup[v] = #tables
 end
 file:write( charS.."{"..lookup[v].."},"..charE )
 elseif type( v ) == "function" then
 file:write( charS.."loadstring("..exportstring(string.dump( v )).."),"..charE )
 else
 local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
 file:write(  charS..value..","..charE )
 end
 end
 end
 for i,v in pairs( t ) do
 if (not thandled[i]) and type( v ) ~= "userdata" then
 if type( i ) == "table" then
 if not lookup[i] then
 table.insert( tables,i )
 lookup[i] = #tables
 end
 file:write( charS.."[{"..lookup[i].."}]=" )
 else
 local index = ( type( i ) == "string" and "["..exportstring( i ).."]" ) or string.format( "[%d]",i )
 file:write( charS..index.."=" )
 end
 if type( v ) == "table" then
 if not lookup[v] then
 table.insert( tables,v )
 lookup[v] = #tables
 end
 file:write( "{"..lookup[v].."},"..charE )
 elseif type( v ) == "function" then
 file:write( "loadstring("..exportstring(string.dump( v )).."),"..charE )
 else
 local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
 file:write( value..","..charE )
 end
 end
 end
 file:write( "},"..charE )
 end
 file:write( "}" )
 if not filename then
 return file.str.."--|"
 elseif filename == true or filename == 1 then
 file:seek ( "set" )
 return file:read( "*a" ).."--|"
 else
 file:close()
 return 1
 end
end

function table.load(sfile)
 local tables, err, _
 if string.sub( sfile,-3,-1 ) == "--|" then
 tables,err = loadstring( sfile )
 else
 tables,err = loadfile( sfile )
 end
 if err then return _,err
 end
 tables = tables()
 for idx = 1,#tables do
 local tolinkv,tolinki = {},{}
 for i,v in pairs( tables[idx] ) do
 if type( v ) == "table" and tables[v[1]] then
 table.insert( tolinkv,{ i,tables[v[1]] } )
 end
 if type( i ) == "table" and tables[i[1]] then
 table.insert( tolinki,{ i,tables[i[1]] } )
 end
 end
 for _,v in ipairs( tolinkv ) do
 tables[idx][v[1]] = v[2]
 end
 for _,v in ipairs( tolinki ) do
 tables[idx][v[2]],tables[idx][v[1]] =  tables[idx][v[1]],nil
 end
 end
 return tables[1]
 end
end

function clearTable(tb)
 for i, v in pairs(tb) do
 tb[i] = nil
 end
end

function tablelength(T)
 local count = 0
 for _ in pairs(T) do count = count + 1 end
 return count
end

function file_check(file_name)
 local file_found=io.open(file_name, "r")
 if file_found==nil then
 return file_found
 else
 io.close(file_found)
 end
 return file_found
end

--- Usage:
mytable = {}

data1 = 'corroder'
data2 = 'dumb'
data3 = 1000

mytable[1] = {data1 = data1, data2 = data2, data3 = data3}

data4 = 'dtrump'
data5 = 'politic'
data6 = 10000

mytable[#mytable+1] = {data1 = data4, data2 = data5, data3 = data6}

data7 = 'bjhonson'
data8 = 'republic'
data9 = 10

mytable[#mytable+1] = {data1 = data7, data2 = data8, data3 = data9}


function save2file()
 player_path = TrainerOrigin or getMainForm()
 table.save(mytable,player_path..'\\userdata.lua')
 showMessage('Data saved')
 return player_path
end

function loadTableFromfile()
 player_path = TrainerOrigin or getMainForm()
 if file_check('userdata.lua') == nil then
 return nil
 else
 mytable = {}
 mytable,err = table.load(player_path..'\\userdata.lua')
 assert( err == nil )
 a =tablelength(mytable)
 print(a)
 for i = 1, #mytable do
   print(mytable[i].data1,mytable[i].data2,mytable[i].data3)
 end

 end
 return player_path
end

save2file()
loadTableFromfile()

-- output:
3   -- table length
corroder dumb 1000
dtrump politic 10000
bjhonson republic 10

-- data table file contains
return {
-- Table: {1}
{
   {2},
   {3},
   {4},
},
-- Table: {2}
{
   ["data3"]=1000,
   ["data2"]="dumb",
   ["data1"]="corroder",
},
-- Table: {3}
{
   ["data3"]=10000,
   ["data2"]="politic",
   ["data1"]="dtrump",
},
-- Table: {4}
{
   ["data3"]=10,
   ["data2"]="republic",
   ["data1"]="bjhonson",
},
}

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
blankTM
Cheater
Reputation: 1

Joined: 03 May 2020
Posts: 49

PostPosted: Fri Jun 26, 2020 3:41 am    Post subject: Re: Create, append multidimentional array table lua Reply with quote

A less perfect way
Can be saved as json to file
Code:

json=decodeFunction([==[c-oy/U2Ggz6,ZXwon3nqw}n]@A+A+u+l}.8lJt,Zyv)eBQkk?;ia/h%YpuOwXUk=ctan:nh/s-qJMH$D7HD7cQn]IVk$6W!nsE^rwK1/CL=u,2NYEhh01rHr?SQs_yN;Ntw7b4Lcka*+:kGh]Tz}CYJ@x,$;RVmueQDL9Iy(aRPwme:FW92{CiXvv-)5CQ,P3uw]Y-!{n%ef7zV9[^r[uDC#ipG++YtBsO=!CxBdq.U51(s4!vspAUkK4lq)Ah9y4NH6mAJ7mgcC^+)M7yp4}T{Opzq]ajpxLR._:e^?m2BCxNN,%oExR[hHPHM9LQQ18-mhWzI.w%-ztbCwB:l}$V))BSd:7]r2a*MZH#+u4:@sU+ul7]k]#/2Nh}F*ut-W^O;hbC:MtDtkvAeJxD19zvHl9ykAmiCidGiM@08K(OObOK;r?AAERx*H89Etx.]Q^o-?Tr]^KOk2oN.kP)si6Sg#[email protected]]ci[1**G]oDtdWLQFCm]Yc5-FHkX(sthew*vwn@zn*M4j)X3zMiDtdsTw7X3TSPn8OfJ9O9811*9dxwRUDuZtrTyi14#7{_NYewbkLsL!-mT6RD]k}DeE+UAA5ijyk[VOSP.yGi-Ac_VnO3r[WS5dvB_DX?Dfvy6Je?CA:aecJODb8+PnBGinyXcd/yn.}+H2BkRn.,7sg(G(S#^Pb?swMht]uA*vr0{Vc}.4x[]tfdYSp?^k}8[zoU5#Iy.OoTfJJ#($s/aFwFi{aNXdtld[;7[Dfy[9k12VdlE./(iAoh+rp?jsD8ue{1noidn)V;?E:0;^?4]8HZK0QKpU!Jr1U{Jj.ZQ%!xuS[Cw5FLzM.7Y^9JXYesZ;wpYbseEIQ-DOvZl[_T++gB,WvV2=NM^SOho6$beYRgM%wA}ZL{#gNw:S36!EL!n*FBL.}[o)l}2(]*uh*j0s(_Pk8y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X?,gtz2NhG#3^S:/iwcW;i+FLoaexqdjhlW^tK61+!B+0]{sE#PVx4RJtnX;rUkae,DIf])JO/kZf4d,ij:K]nC;0!YUN1JZdDB=[niFG8DXPBMKAPI3)L_GlsT;QM{$Rt(QLwSbVuu0e-3nR#p3Fv0hLJ6c^lI5EhVjlrSV#Jfd$2NORCD(Gs0H4!O]8M^pS%PUIn)Oc)?fFy2Gpn!nv!/(6PRw^Cf^37R1a++CizY*[9;8zuo+h+*ovtxsPd1HbX^V9w_n}W)#W76LjI2_#Bu2E;r(K-/-mTy}oTgD6nj*@[EHS!hjuC{2cAI#:wIF[2Jn_$ExHXrB[;1^r63WwK1AGnh+gZxi9?MlL5UxS#Rcb(1!,6d.3NkGDBv_--5KpN5R,H^=1r-ArRBlhj!qc22P06]sxqQWM:)?fgzZ:0].cI):B!6$QN9K}v0f5qrM^AUXT=GpG!9ViQadyd0VYffuUyMl_41E6IRw2;{c:b=Dout}:Es$}1;7T1kYT^qa0IA5KupK=+hRc6A:T*1#3J6ow],fJ}jR=QbnZ1UNBbt+sWT4BMH4sA%E@Z6f1d_r6]==])()

mytable = {
{ data1 = 'someone',  data2 = 'something',  data3 = somenumber},
{ data1 = 'corroder',  data2 = 'dumb',  data3 = 1000},
{ data1 = 'someoned',  data2 = 'somdething',  data3 = somednumber}
}
data={data1 = 'avcxa',  data2 = 'dumb',  data3 = 1000}

function addTblItem(mytable,data)
for i=1,#mytable do
 for key,value in pairs(mytable[i]) do
  if value ~= data[key]  then
    if i==#mytable then
    print('Data not found')
    mytable[i+1]=data
    else
    break
    end
   else
    if key=='data3' then
    print('Data exist')
   goto label
    end
  end
 end
end
::label::
end

addTblItem(mytable,data)
print(mytable[1].data1)
e=json.encode(mytable)
print(e)
d=json.decode(e)
print(d[1].data1)


Need to optimize
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Jun 26, 2020 7:53 am    Post subject: Reply with quote

Quote:
blankTM : A less perfect way
Can be saved as json to file


Yes, the good way also if we want to make the table as online table. Use JSON to encode/decode the script including the table.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
blankTM
Cheater
Reputation: 1

Joined: 03 May 2020
Posts: 49

PostPosted: Sat Jun 27, 2020 11:01 pm    Post subject: Reply with quote

The perfect way
Code:

function addTblItem(mytable,data)
for i=1,#mytable do
 for key,value in pairs(mytable[i]) do
  if value ~= data[key]  then
    if i==#mytable then
    print('Data not found')
    mytable[i+1]=data
    else
    goto label
    end
   end
  end
  print('Data exist')
  break
  ::label::
 end
end
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites