Cuberite Forum
How add a function to existing class - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: How add a function to existing class (/thread-2956.html)



How add a function to existing class - moiko89 - 05-20-2017

hi there,

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

Example:


cPlayer:getBedPos(World)


RE: How add a function to existing class - xoft - 05-20-2017

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.


RE: How add a function to existing class - moiko89 - 05-20-2017

(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?


RE: How add a function to existing class - xoft - 05-20-2017

What, you mean you want to add a method to a class from a plugin? That's impossible.


RE: How add a function to existing class - NiLSPACE - 05-21-2017

No it's not, I did it before with cBlockArea: https://forum.cuberite.org/thread-569-post-15474.html#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.


RE: How add a function to existing class - xoft - 05-21-2017

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.