Skip to content

Commit f13282e

Browse files
committed
Clean-up and bug fixes to Lua bindings:
- Fixed a regression introduced in v3.0 that could cause a Lua stack leak, causing eventual crash in some Lua-based games. - Fixed a number of problematic and potentially unsafe Lua usage scenarios, where passing a subclass object to a function that expects a base class could cause a crash. This fix was accomplished by adding support for automatic and safe conversion between base classes and subclasses (and vice-versa) when passing objects from Lua to C++. - Removed the global 'convert' Lua function since it was unsafe. Instead, when manual object casting is required in Lua, such as when needing to convert a base class to a known subclass to access subclass-specific interfaces, the Lua bindings now support a safe 'to(type)' function on all polymorphic classes. - When using the new built-in 'to(type)' conversion function, nil will be returned if no suitable conversion exists. Similarly, when attempting to pass an incompatible object type to a Lua C++ function, the function will gracefully fail and log a script error.
1 parent 79f1a31 commit f13282e

File tree

285 files changed

+14177
-12448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+14177
-12448
lines changed

gameplay/src/Base.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <set>
2323
#include <stack>
2424
#include <map>
25+
#include <unordered_map>
2526
#include <queue>
2627
#include <algorithm>
2728
#include <limits>
@@ -116,7 +117,7 @@ extern int strcmpnocase(const char* s1, const char* s2);
116117
#pragma warning( disable : 4244 )
117118
#pragma warning( disable : 4267 )
118119
#pragma warning( disable : 4311 )
119-
#pragma warning( disable : 4316 )
120+
#pragma warning( disable : 4316 )
120121
#pragma warning( disable : 4390 )
121122
#pragma warning( disable : 4800 )
122123
#pragma warning( disable : 4996 )

gameplay/src/Joint.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ Node::Type Joint::getType() const
3535
return Node::JOINT;
3636
}
3737

38+
const char* Joint::getTypeName() const
39+
{
40+
return "Joint";
41+
}
42+
3843
Scene* Joint::getScene() const
3944
{
4045
// Overrides Node::getScene() to search the node our skins.

gameplay/src/Joint.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ class Joint : public Node
3434
*/
3535
Scene* getScene() const;
3636

37+
/**
38+
* Extends ScriptTarget::getTypeName() to return the type name of this class.
39+
*
40+
* @return The type name of this class: "Joint"
41+
* @see ScriptTarget::getTypeName()
42+
*/
43+
const char* getTypeName() const;
44+
3745
/**
3846
* Returns the inverse bind pose matrix for this joint.
3947
*

gameplay/src/Logger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void Logger::log(Level level, const char* message, ...)
6565
else if (state.logFunctionLua)
6666
{
6767
// Pass call to registered Lua log function
68-
Game::getInstance()->getScriptController()->executeFunction<void>(state.logFunctionLua, "[Logger::Level]s", level, str);
68+
Game::getInstance()->getScriptController()->executeFunction<void>(state.logFunctionLua, "[Logger::Level]s", NULL, level, str);
6969
}
7070
else
7171
{

gameplay/src/PhysicsCollisionObject.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ void PhysicsCollisionObject::ScriptListener::collisionEvent(PhysicsCollisionObje
325325
{
326326
Game::getInstance()->getScriptController()->executeFunction<void>(function.c_str(),
327327
"[PhysicsCollisionObject::CollisionListener::EventType]<PhysicsCollisionObject::CollisionPair><Vector3><Vector3>",
328+
NULL,
328329
type, &collisionPair, &contactPointA, &contactPointB);
329330
}
330331

gameplay/src/Scene.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ void Scene::visitNode(Node* node, const char* visitMethod)
200200
ScriptController* sc = Game::getInstance()->getScriptController();
201201

202202
// Invoke the visit method for this node.
203-
if (!sc->executeFunction<bool>(visitMethod, "<Node>", dynamic_cast<void*>(node)))
203+
bool result;
204+
if (!sc->executeFunction<bool>(visitMethod, "<Node>", &result, (void*)node) || !result)
204205
return;
205206

206207
// If this node has a model with a mesh skin, visit the joint hierarchy within it

0 commit comments

Comments
 (0)