如何追踪我的恭维顺序? (这样我可以重新订购它)
我的问题: 我正在运行Visual Studio 2012编写C ++应用程序。我使用LuaBind
将脚本系统Lua绑定到我的项目中LuaBind隐藏Lua的东西并弄清楚如何将它绑定到Lua语言(或一些魔法)
我可以获取一个对象,在其上调用一个函数,并传入一个C ++对象,以便给予lua脚本函数
// ScriptComponent.h
class ScriptComponent : public Component
{
public:
virtual void Initialize();
virtual void Update();
protected:
luabind::object luaDataTable;
Entity* mOwner;
-
// ScriptComponent.cpp
void ScriptComponent::Initialize() {
luabind::object compiledScript;
luaL_loadfile(L, "myScript.lua");
luabind::object compiledScript(luabind::from_stack(L, -1));
luaDataTable = compiledScript();
lua_pop(L, 1);
}
void ScriptComponent::Update() {
luaDataTable["run"](mOwner); // Compiler breaks here.
// Note: if I remove mOwner from the mix (and in the script file) everything works and runs fine.
}
酷!但为了让这个工作起作用,luabind需要知道mOwner(实体*)是什么,并且已经定义了。所以,我在另一个文件中定义它:
// GameScriptingSystem.cpp
using namespace luabind;
module(inLuaState)
[
class_<GameObject>("GameObject"),
class_<Entity, bases<GameObject> >("Entity")
.def("DebugGetName", &Entity::DebugGetName)
];
流程看起来像这样:
结果:
错误C2504:'实体':基类未定义
要求完整错误:
...
2> Component.cpp
2> ScriptComponent.cpp
2>boost/type_traits/is_polymorphic.hpp(46): error C2504: 'Entity' : base class undefined
2> boost/type_traits/is_polymorphic.hpp(62) : see reference to class template instantiation 'boost::detail::is_polymorphic_imp1<T>::d2' being compiled
2> with
2> [
2> T=Entity
2> ]
2> boost/type_traits/is_polymorphic.hpp(97) : see reference to class template instantiation 'boost::detail::is_polymorphic_imp1<T>' being compiled
2> with
2> [
2> T=Entity
2> ]
2> boost/type_traits/is_polymorphic.hpp(102) : see reference to class template instantiation 'boost::detail::is_polymorphic_imp<T>' being compiled
2> with
2> [
2> T=Entity
2> ]
2> luabind/detail/make_instance.hpp(42) : see reference to class template instantiation 'boost::is_polymorphic<T>' being compiled
2> with
2> [
2> T=Entity
2> ]
2> luabind/detail/make_instance.hpp(74) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2> luabind::detail::get_dynamic_class<T>(lua_State *,T *)' being compiled
2> with
2> [
2> _Ty1=luabind::detail::class_id,
2> _Ty2=void *,
2> T=Entity
2> ]
2> luabind/detail/policy.hpp(228) : see reference to function template instantiation 'void luabind::detail::make_instance<T*>(lua_State *,P)' being compiled
2> with
2> [
2> T=Entity,
2> P=Entity *
2> ]
2> luabind/detail/convert_to_lua.hpp(87) : see reference to function template instantiation 'void luabind::detail::pointer_converter::apply<Entity>(lua_State *,T *)' being compiled
2> with
2> [
2> T=Entity
2> ]
2> luabind/object.hpp(1072) : see reference to function template instantiation 'void luabind::detail::convert_to_lua_p<1,Entity*,Policies>(lua_State *,const T &,const Policies &)' being compiled
2> with
2> [
2> Policies=luabind::detail::null_type,
2> T=Entity *
2> ]
2> luabind/object.hpp(1140) : see reference to function template instantiation 'void luabind::detail::push_args_from_tuple<Index>::apply<T0,boost::tuples::detail::map_tuple_to_cons<boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>::type,luabind::detail::null_type>(lua_State *,const boost::tuples::cons<HT,TT> &,const Policies &)' being compiled
2> with
2> [
2> Index=1,
2> T0=Entity *const *,
2> HT=Entity *const *,
2> TT=boost::tuples::detail::map_tuple_to_cons<boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>::type,
2> Policies=luabind::detail::null_type
2> ]
2> luabind/object.hpp(1140) : see reference to function template instantiation 'void luabind::detail::push_args_from_tuple<Index>::apply<T0,boost::tuples::detail::map_tuple_to_cons<boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>::type,luabind::detail::null_type>(lua_State *,const boost::tuples::cons<HT,TT> &,const Policies &)' being compiled
2> with
2> [
2> Index=1,
2> T0=Entity *const *,
2> HT=Entity *const *,
2> TT=boost::tuples::detail::map_tuple_to_cons<boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>::type,
2> Policies=luabind::detail::null_type
2> ]
2> luabind/object.hpp(1112) : see reference to function template instantiation 'luabind::adl::object luabind::adl::call_proxy<ValueWrapper,Arguments>::call<luabind::detail::null_type>(Policies *)' being compiled
2> with
2> [
2> ValueWrapper=luabind::adl::index_proxy<luabind::adl::object>,
2> Arguments=boost::tuples::tuple<Entity *const *,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>,
2> Policies=luabind::detail::null_type
2> ]
2> luabind/object.hpp(1112) : see reference to function template instantiation 'luabind::adl::object luabind::adl::call_proxy<ValueWrapper,Arguments>::call<luabind::detail::null_type>(Policies *)' being compiled
2> with
2> [
2> ValueWrapper=luabind::adl::index_proxy<luabind::adl::object>,
2> Arguments=boost::tuples::tuple<Entity *const *,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>,
2> Policies=luabind::detail::null_type
2> ]
2> luabind/object.hpp(1110) : while compiling class template member function 'luabind::adl::call_proxy<ValueWrapper,Arguments>::~call_proxy(void)'
2> with
2> [
2> ValueWrapper=luabind::adl::index_proxy<luabind::adl::object>,
2> Arguments=boost::tuples::tuple<Entity *const *,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>
2> ]
2> ..\src\Game\GameObjects\Components\ScriptComponent.cpp(75) : see reference to function template instantiation 'luabind::adl::call_proxy<ValueWrapper,Arguments>::~call_proxy(void)' being compiled
2> with
2> [
2> ValueWrapper=luabind::adl::index_proxy<luabind::adl::object>,
2> Arguments=boost::tuples::tuple<Entity *const *,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>
2> ]
2> ..\src\Game\GameObjects\Components\ScriptComponent.cpp(75) : see reference to class template instantiation 'luabind::adl::call_proxy<ValueWrapper,Arguments>' being compiled
2> with
2> [
2> ValueWrapper=luabind::adl::index_proxy<luabind::adl::object>,
2> Arguments=boost::tuples::tuple<Entity *const *,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>
2> ]
2>boost/type_traits/is_polymorphic.hpp(34): error C2504: 'Entity' : base class undefined
2> boost/type_traits/is_polymorphic.hpp(62) : see reference to class template instantiation 'boost::detail::is_polymorphic_imp1<T>::d1' being compiled
2> with
2> [
2> T=Entity
2> ]
2> Map.cpp
2> Generating Code...
2> Compiling...
2> GameScriptingSystem.cpp
2> PoCToolsInterface.cpp
..
据我所知,由于构建顺序。我最好的猜测是Luabind在编译时完成所有这些工作,当我首先查看编译时,首先编译 ScriptComponent ,之后编译 GameScriptSystem。当ScriptComponent构建时,通过luabind错误。然后在GameScriptSystem构建之后(定义了LuaBind抱怨的所有东西)
所以:
如何跟踪构建订单?看看哪些文件触发了其他人的构建,以便我可以根据自己的喜好重新安排它? (这是一个很大的项目,它不像看它那么容易2秒)
如果你认识luabind,我对此是否正确?
其他数据:
-- myScript.lua
local Cat = {}
local ticks = 0
function Cat.run(entity)
ticks = ticks + 1
LOG(tostring(ticks))
LOG(entity:DebugGetName())
end
return Cat
答案 0 :(得分:2)
不,这不是因为构建订单。 C ++编译单元独立构建。即使已经编译了定义您的实体的.cpp文件,它也不会自动可用。
C ++永远不会搜索实体的定义。在编译单元中使用实体的唯一方法是在该编译单元中存在该实体的声明(取决于用法,您可能只需要前向声明或完整定义)。通常使用头文件和#include
来避免代码重复。