AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   PUBLIC and STOCK (https://forums.alliedmods.net/showthread.php?t=10775)

TotalNoobScripter 02-28-2005 18:42

PUBLIC and STOCK
 
whats the diff between PUBLIC and STOCK? im feeling really noobish by askin this question..

Twilight Suzuka 02-28-2005 19:03

You should not feel noobish for not knowing this information...there are many many other things you can feel noobish about.

I believe there are five types of functions in SMALL for AMXX.

Normal - functions w/o a definition
ex.
Code:
  func_area(Float:length,Float:width){return (length*width)}

Used:
When you want a function no one else can call, or its basically an inline (could simply be incorporated into other functions, but easier to make it its own)

Public - functions that are "public", that is, other plugins and AMXX itself can communicate through them

ex.
Code:
public func_area(Float:length,Float:width){return (length*width)}

Used:
Functions used for commands, tasks, etc etc. They are "public" to other AMXX plugins and such. I think they use a little more CPU and such.

Native - A function provided by a module or AMXX itself. It is "native" to the plugin that is to say, you do not have to remake it in SMALL.

ex.
Code:
replace(source[],with[],len)

Stock - the closest to "inlines" from C++. These are like natives, but you build them yourself. I believe that when you mark a function as stock, every time you use that function, the place where you used it is actually REPLACED by the stock function.

ex.
Code:
stock func_area(Float:length,Float:width){return (length*width)}

Now, every declaration of "func_area" is replaced by "length*width" or something similar. I might be wrong on that one.

The upshot is, stocks are not checked, and work like natives, but you make them on your own.

Forwards - Just like publics, but called when AMXX wants them to be called.

ex:
Code:
public client_prethink(id)

Those are the five, general function types in SMALL/AMXX scripting...I think. I could be wrong. Anyway, thats the difference between public and stock. One is open to all of AMXX to call, one is used as sort of a memory saving manuever.

PM 03-03-2005 16:23

Some corrections:

1) public functions are just functions that AMXX can see.
2) The difference between "normal" and stock functions is that stock functions are not included in the output file if the function is unused
3) The forward declarations just tell the compiler which prototype a function should have

Twilight Suzuka 03-03-2005 16:49

Right....right...
I forgot exactly what the stock would do to be similar to inlines, and thats it.

But anyway, I think he understood.


All times are GMT -4. The time now is 14:11.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.