Torque3D/Engine/source/cinterface/cinterface.cpp

96 lines
3.3 KiB
C++
Raw Normal View History

2012-09-19 15:15:01 +00:00
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
2018-04-21 08:11:01 +00:00
#include "cinterface.h"
2012-09-19 15:15:01 +00:00
#include "console/compiler.h"
#include "windowManager/platformWindow.h"
2018-04-21 08:11:01 +00:00
CInterface& CInterface::GetCInterface()
{
static CInterface INSTANCE;
return INSTANCE;
}
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
bool CInterface::isMethod(const char* className, const char* methodName)
{
return GetCInterface()._isMethod(className, methodName);
}
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
const char* CInterface::CallFunction(const char* nameSpace, const char* name, const char **argv, int argc, bool *result)
{
return GetCInterface()._CallFunction(nameSpace, name, argv, argc, result);
2012-09-19 15:15:01 +00:00
}
2018-04-21 08:11:01 +00:00
const char* CInterface::CallMethod(SimObject* obj, const char* name, const char **argv, int argc, bool *res)
2012-09-19 15:15:01 +00:00
{
2018-04-21 08:11:01 +00:00
return GetCInterface()._CallMethod(obj->getClassName(), obj->getClassNamespace(), obj->getId(), name, argv, argc, res);
}
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
void CInterface::CallMain(bool *res)
{
GetCInterface()._CallMain(res);
}
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
bool CInterface::_isMethod(const char* className, const char* methodName) const
{
if (mIsMethodCallback)
return mIsMethodCallback(className, methodName);
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
return NULL;
}
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
const char* CInterface::_CallFunction(const char* nameSpace, const char* name, const char **argv, int argc, bool *result) const
{
if (mFunctionCallback)
return mFunctionCallback(nameSpace, name, argv, argc, result);
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
*result = false;
return NULL;
2012-09-19 15:15:01 +00:00
}
2018-04-21 08:11:01 +00:00
const char* CInterface::_CallMethod(const char* className, const char* classNamespace, U32 object, const char* name, const char **argv, int argc, bool *res) const
{
if (mMethodCallback)
return mMethodCallback(className, classNamespace, object, name, argv, argc, res);
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
*res = false;
return NULL;
}
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
void CInterface::_CallMain(bool *res) const
{
if (mMainCallback)
{
*res = true;
mMainCallback();
return;
}
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
*res = false;
}
2012-09-19 15:15:01 +00:00
2018-04-21 08:11:01 +00:00
TORQUE_API void SetCallbacks(void* ptr, void* methodPtr, void* isMethodPtr, void* mainPtr) {
CInterface::GetCInterface().SetCallFunctionCallback(ptr);
CInterface::GetCInterface().SetCallMethodCallback(methodPtr);
CInterface::GetCInterface().SetCallIsMethodCallback(isMethodPtr);
CInterface::GetCInterface().SetMainCallback(mainPtr);
}