Jump to content

[SOLVED] How to register multiple definitions of single extern class?


photo

Recommended Posts

Posted

I am trying to export to UnigineScript multiple classes (with different names of course) that are tied to the same actual C++ class. App compiles but gives errors on world load

Interpreter::addExternClass(): "foo" class is already defined

If I try to use this class in UnigineScript:

Interpreter::parse(): unknown token "foo"

Is there a way to accomplish this without creating a new C++ class?

Posted

Hi Adam, you can do it like this: 

        ExternClass<NameOfCPlusPlusClass> *instance = MakeExternClass<NameOfCPlusPlusClass>();
	Interpreter::addExternClass("ScriptClassName",instance);

	ExternClass<NameOfCPlusPlusClass> *instance2 = MakeExternClass<NameOfCPlusPlusClass>();
	Interpreter::addExternClass("ScriptClassName2",instance2);
Posted

Sorry for delayed response -- I have been away from work.

 

maxi, the example you gave matches my current implementation. Two separate ExternClass<foo> pointers are created, each passed to Interpreter::addExternClass with separate names. This results in the errors I initially posted, with the Interpreter failing to register the second one claiming it has already been defined.

 

Should I submit a test scenario?

Posted

Here you go.

 

Build with Visual Studio 2013

copy resulting PluginTest.DLL into bin directory of existing Unigine project

add "PluginTest" to extern_plugin setting in Unigine project's launcher or in system config

Launch Unigine project

Interpreter::addExternClass(): "fooAgain" class is already defined

fooAgain class is thereafter unavailable to UnigineScript.

PluginTest.zip

Posted

Hi Adam,

 

Sorry for the wrong answer. Indeed, you can't add two extern classes with the same typeinfo. You need to reorganize your code logic in some way.

×
×
  • Create New...