simplex Posted April 28, 2014 Share Posted April 28, 2014 well, according to this http://stackoverflow.com/questions/17763223/lua-table-address-and-address-tabletwo runs of lua interpreter show same address e$ luaLua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio> print({})table: 0x7fdaca4098c0> ^De$ luaLua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio> print({})table: 0x7fb02a4098c0> ^De$but like in any interpreter - its not real memory address, its just emulation and for my task its doesnt matter.The point made in that StackOverflow thread is that the addresses are not the same, as you can see by looking at your code snippet (it just happens that the addresses have the same prefix and suffix; the differ in the middle).And it's not an "emulated" address, it's a real memory address. It's not a physical memory address, but that's due to the OS's virtual memory mapping: it'd be the same situation in a program run directly, such as a C or Assembly application.To track the onattacked function set up by the follower component, you can use address comparison because the components uses the same onattacked function for every entity, so the address is the same within one instance of the game (but not throughout different instances). Though you don't need to actually extract the address via tostring() or something like that, you can simply use an equality test between functions.But that's far from ideal. Just remove the callback based on its source:local _G = GLOBALlocal debug = _G.debug--[[--// Removes the "attacked" callback set up within the prefabs/abigail.lua--// file.--]]AddPrefabPostInit("abigail", function(inst) --// Will store the "attacked" callback set up by prefabs/abigail.lua local onattacked if inst.event_listening.attacked and inst.event_listening.attacked[inst] then for _, fn in ipairs(inst.event_listening.attacked[inst]) do local info = debug.getinfo(fn, "S") if info and info.source then if info.source:match("prefabs[/\\]abigail.lua$") then onattacked = fn break end end end end if onattacked then inst:RemoveEventCallback("attacked", onattacked) endend) Link to comment Share on other sites More sharing options...
Rincevvind Posted April 28, 2014 Author Share Posted April 28, 2014 wow so thats lua magic that i asked forlocal info = debug.getinfo(fn, "S") if info and info.source then if info.source:match("prefabs[/\\]abigail.lua$") then onattacked = fn break end endbig thx.there also "debug.getlocal" to learn Link to comment Share on other sites More sharing options...
simplex Posted April 28, 2014 Share Posted April 28, 2014 there also "debug.getlocal" to learn debug.getlocal is rarely useful, because you can only get local variables of functions that are currently running (i.e., a function that called your current function, or the one that called that, and so on; in Lua a file is just a function, whose body is the contents of the file). debug.getupvalue is what you're looking for. But using the debug library should be considered a last resort: slight misuse may cause huge bugs, and these functions are slow. If you can do things some other way (unless it's something just as hackish, like getting memory addresses ), then do things some other way. Link to comment Share on other sites More sharing options...
Rincevvind Posted April 28, 2014 Author Share Posted April 28, 2014 one more question Though you don't need to actually extract the address via tostring() or something like that,addresses can't be compared directly? i have to compare tostring() from both? Link to comment Share on other sites More sharing options...
Rincevvind Posted April 28, 2014 Author Share Posted April 28, 2014 and these functions are slowwell i am going to use them only for init functions, dont think that its problem here. Link to comment Share on other sites More sharing options...
simplex Posted April 28, 2014 Share Posted April 28, 2014 well i am going to use them only for init functions, dont think that its problem here. It's not (and debug.getinfo itself is not slow). I just said this as general advice against overuse of the debug library. Link to comment Share on other sites More sharing options...
_Q_ Posted April 28, 2014 Share Posted April 28, 2014 All that stuff just to edit one function call ?Really? Link to comment Share on other sites More sharing options...
simplex Posted April 28, 2014 Share Posted April 28, 2014 All that stuff just to edit one function call ? Really? Not edit a function call, extract a local function added as an event callback. Much trickier . Though of course it'd be much simpler for us if event callbacks were added together with a unique string which could be used to reference them. Since this is not the case, and the only identifier is the function itself, there's to way to avoid extra complexity. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.