how to batch change the field of the table in lua -
in lua, want change field name of table, like
in test1.lua
local t = { player_id = 2, item_id = 1, } return t
in test2.lua
local t = require "test1" print( t.item_id )
if want change field name item_id
-> item_count
of t
,
i need use application ultraedit
, find out lua file contain item_id
, , modified 1 one, such modification easy correction or change of leakage, there tools can more modified field name?
if understand problem correctly:
(what if item_id happens field in different table?)
in view, there no generic solution task without interpreting script. field name (e.g., item_id) appear in many places referring different tables. make sure change references correct table need interpret script. given dynamic nature of lua scripts, not trivial task.
using editor (or preferably lua script) globally replace occurrences of 1 name work if you're 'old' name has single context.
a run-time workaround might add metatable keep both new , old name. think need play __index , __newindex events. then, same field accessed either 'old' or 'new' name.
example metatable trick (only field 'one' part of table, field 'two' access made possible via metatable read/write field 'one' reading 'two' reads 'one', while writing 'two' writes 'one'):
t = {} t.one = 1 setmetatable(t,{__index = function(t,k) if k == 'two' return t.one end end, __newindex = function(t,k,v) if k == 'two' t.one = v end end }) print(t.one,t.two) t.two = 2 print(t.one,t.two)
Comments
Post a Comment