axmol/testjs/Classes/simple_class.cpp

53 lines
1.0 KiB
C++
Raw Normal View History

2012-05-28 16:58:16 +08:00
/**
* Simple example of a C++ class that can be binded using the
* automatic script generator
*/
#include "simple_class.h"
SimpleNativeClass::SimpleNativeClass()
{
// just set some fields
m_someField = 0;
m_someOtherField = 10;
m_anotherMoreComplexField = NULL;
2012-05-28 16:58:16 +08:00
}
// empty destructor
SimpleNativeClass::~SimpleNativeClass()
{
}
// just a very simple function :)
int SimpleNativeClass::doSomeProcessing(std::string arg1, std::string arg2)
{
return arg1.length() + arg2.length();
2012-05-28 16:58:16 +08:00
}
void SimpleNativeClass::setAnotherMoreComplexField(const char *str)
{
if (m_anotherMoreComplexField) {
free(m_anotherMoreComplexField);
}
size_t len = strlen(str);
m_anotherMoreComplexField = (char *)malloc(len);
memcpy(m_anotherMoreComplexField, str, len);
2012-05-28 16:58:16 +08:00
}
namespace SomeNamespace
{
AnotherClass::AnotherClass()
{
justOneField = 1313;
aPublicField = 1337;
2012-05-28 16:58:16 +08:00
}
// empty destructor
AnotherClass::~AnotherClass()
{
}
void AnotherClass::doSomethingSimple() {
fprintf(stderr, "just doing something simple\n");
2012-05-28 16:58:16 +08:00
}
};