Problem using the 'SECS' class library
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Problem using the 'SECS' class library
Because 'self' is not 'obj'. They're two distinct variables, and you can't modify one with the other (just the table they both point to).
Re: Problem using the 'SECS' class library
And how can I fix this?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Problem using the 'SECS' class library
Like this:
Code: Select all
function love.load()
require "class"
object = class:new()
function object:init()
end
obj = object:new()
obj = nil -- don't forget to clear the other references to the object as well
print(obj) -- prints nil
end
Help us help you: attach a .love.
Re: Problem using the 'SECS' class library
It's important for me to have a function for that. And doing it the easiest way I can think of doesn't work either:
Code: Select all
function love.load()
require "class"
function object_destroy(o)
o = nil
-- note that I don't want to use 'return nil' here and write 'obj = object_destroy()'
-- because I need to use this argument for other purposes too
end
object = class:new()
function object:init()
end
obj = object:new()
object_destroy(obj)
print(obj) -- still prints table
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Problem using the 'SECS' class library
Why?Zephos wrote:It's important for me to have a function for that.
It looks like you don't understand how Lua works and how garbage collection works. I want to help you but I don't know where to begin.
Help us help you: attach a .love.
Re: Problem using the 'SECS' class library
Because I need to use the argument 'o' in the function for other purposes too other than setting it to nil. Take a look at it.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Problem using the 'SECS' class library
Well, you simply can't set it to nil.
Re: Problem using the 'SECS' class library
By the way, I can't set it to anything else either, actually. Are you telling me that there is no fix for this seemingly simple problem?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Problem using the 'SECS' class library
This is a textbook case of the X-Y problem. Why do you want to destroy objects in the first place? In Lua, you don't have to.Zephos wrote:Are you telling me that there is no fix for this seemingly simple problem?
Help us help you: attach a .love.
Re: Problem using the 'SECS' class library
Let Y be the main problem here now. My X should be irrelevant for you as long as I know exactly what I want, anyway. Just please give me the answer to my problem and let me be happy, especially if the solution is exactly as easy as I imagined it to be:
Now, is there anything to complain about this? In the end, that's all I wanted to know.
Code: Select all
function object_destroy(objstr)
loadstring(objstr .. " = 'whateverthefuckiwant'")()
end
...
object_destroy("obj")
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 11 guests