Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: EK.IceFlake on Sep 17, 2016, 06:47 PM

Title: Calling a function if it exists?
Post by: EK.IceFlake on Sep 17, 2016, 06:47 PM
After so many servers I have made, I got some experience in how to make your code tidy and extensible. I am writing a modular interface which will have to call lots of functions for an event, but only if they exist.

Any idea how to do it?

Thanks
Title: Re: Calling a function if it exists?
Post by: EK.IceFlake on Sep 18, 2016, 11:32 AM
Okay, thanks :)
Title: Re: Calling a function if it exists?
Post by: . on Sep 18, 2016, 11:42 AM
if (my_table/class/instance/whatever.rawin("somefunc"))
    my_table/class/instance/whatever.rawget("somefunc").call(this, "sup?");

Worst design decision you could make. Because it involves iterating over a container multiple times to locate something.
Title: Re: Calling a function if it exists?
Post by: EK.IceFlake on Sep 18, 2016, 12:26 PM
Quote from: . on Sep 18, 2016, 11:42 AMif (my_table/class/instance/whatever.rawin("somefunc"))
    my_table/class/instance/whatever.rawget("somefunc").call(this, "sup?");

Worst design decision you could make. Because it involves iterating over a container multiple times to locate something.
Wow... I was experimenting and tried .rawexists instead of .rawin
:v