• Can I use return in hooks safely ?
    7 replies, posted
Hi, I always wondered if I could just use if SOME_CONDITION then return end in my hooks without breaking anything ? Thanks,
Yes, you can do that.
Why don't you try it first?
I tried it and it didn't break anything LoweChaser, but i wanted to know if it was ok.
When you use return without any arguments, you are essentially returning nil. A function with no return instruction returns nil. From the outside, your hook just looks like any hook.
Returning nil vs nothing is actually different - while this usually won't affect Lua->Lua function calls, it can affect C->Lua calls. This behaviour can be seen with: local function f1() return end local function f2() return nil end print(type(f1())) -- no value print(type(f2())) -- nil Won't affect hooks but there is a difference.
What the fuck
You can see the difference in Lua when using select, print(select('#', f1())) -- 0 print(select('#', f2())) -- 1
Sorry, you need to Log In to post a reply to this thread.