Cuberite Forum

Full Version: How add a function to existing class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi there,

how i can add a function/parameter to a existing class like cPlayer?

Example:


cPlayer:getBedPos(World)
You need to implement the function in C++ code, and in the .h file, mark it with an "// tolua_export" comment right after the declaration. Then you need to document the API - that's in the Server/Plugins/APIDump folder; the format should be pretty self-explanatory.
(05-20-2017, 12:54 AM)xoft Wrote: [ -> ]You need to implement the function in C++ code, and in the .h file, mark it with an "// tolua_export" comment right after the declaration. Then you need to document the API - that's in the Server/Plugins/APIDump folder; the format should be pretty self-explanatory.


Okay thanks... do you know if other plugins exist for an example?
What, you mean you want to add a method to a class from a plugin? That's impossible.
No it's not, I did it before with cBlockArea: https://forum.cuberite.org/thread-569-po...l#pid15474

cPlayer was a bit harder to do. First I had to get rid of the metatable, put the function inside and then put the metatable in there again.
It has such limits that it's not worth doing. I assume the original request is to make a plugin that adds an API function for other plugins to use, so this won't work. And as noted, the custom functions and variables may not survive for long.