gpt4 book ai didi

c++ - 了解编译顺序、编译错误和由于基类未定义而导致的 luabind

转载 作者:行者123 更新时间:2023-11-30 04:10:15 25 4
gpt4 key购买 nike

如何追踪我的合规订单? (这样我就可以重新订购)

我的问题:我正在运行 Visual Studio 2012 编写 C++ 应用程序。我使用 LuaBind 将脚本系统 Lua 绑定(bind)到我的项目

LuaBind 隐藏了 Lua 的东西并弄清楚如何将它绑定(bind)到 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 (Entity*) 是什么并且定义了 ti。所以,我在不同的文件中定义它:

// GameScriptingSystem.cpp
using namespace luabind;
module(inLuaState)
[
class_<GameObject>("GameObject"),
class_<Entity, bases<GameObject> >("Entity")
.def("DebugGetName", &Entity::DebugGetName)
];

流程看起来像这样: enter image description here

结果:

error C2504: 'Entity' : base class undefined

请求的完整错误:

...
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

最佳答案

不,这不是因为构建顺序。 C++ 编译单元独立构建。即使定义实体的 .cpp 文件已经编译,它也不会自动可用。

C++ 从不去寻找实体的定义。在编译单元内使用实体的唯一方法是声明该实体存在于该编译单元中(根据用途,您可能只需要前向声明或完整定义)。通常使用头文件和#include 来避免代码重复。

关于c++ - 了解编译顺序、编译错误和由于基类未定义而导致的 luabind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20722627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com