C++ Plugin export necessary variables,functions and classes

  • Expose library services using CreatePlugin() and ReleasePlugin() functions. They allow the engine to load a dynamic-link library into Unigine executable address space and access the exported functions and variables.
  • 自定义的类继承Unigine  Plugin 类,在其中必须调用CreatePlugin() and ReleasePlugin() functions 来和Engine进行交互.
  • Create a custom plugin class inherited from the Plugin class: define init(), shutdown(), destroy() and other functions.
  • In the plugin initialization function (the init() function), export necessary variables, functions and classes from the library into the script.

以下是一些常用到的函数:

MakeExternFunction():

  Below is an example of function and method export.

  1. Create a pointer to an external function via MakeExternFunction(). For object methods, use MakeExternObjectFunction().
  2. Register the function or a method via Unigine::Interpreter::addExternFunction().
  3. All functions are exported into a global namespace. To limit the scope of the exported function or a method, use library namespace.
 // export functions
 Interpreter::addExternFunction("my_sum",MakeExternFunction(&my_sum,",1"));
 Interpreter::addExternFunction("my_mul",MakeExternFunction(&my_mul));
 Interpreter::addExternFunction("my_dot",MakeExternFunction(&my_dot));


//export the class
// Create a pointer to the object of the external class 
 ExternClass<MyExternClass> *my_class = MakeExternClass<MyExternClass>();
// Register a class constructor. If it was not declared explicitly, a default one will be
    // registered.
 my_class->addConstructor();
// Register a class member function.
 my_class->addFunction("print",&MyExternClass::print);
 // Register the class.
 Interpreter::addExternClass("MyExternClass",my_class);
 
以上就是export functions and classes ,会发现他们之间是有一些区别的:
When export the class we need to make a pointer of this class first,use this pointer to add the member functions which we want to
export, the function is addFunction(). The end we add the class use addExternClass function.

写的中英文混杂,不是很清楚,主要帮助文档是英文的,而且我对帮助文档也不是太懂,先将就着做点笔记,以后熟悉了再重新修改。
对自己的要求是每天写一点,给自己鼓鼓劲。

 

posted @ 2014-08-03 21:46  wzheng  阅读(200)  评论(0编辑  收藏  举报