根据LuaBridge自述文件,LuaBridge不支持"枚举常数",我认为这只是enums.由于sf::Event几乎完全是enums,有没有什么办法,我可以揭露类?目前,我能想出的唯一其他解决方案是在C++中检测按键,然后向Lua发送一个字符串,用于描述事件.显然,在现代键盘上有大约100多个键,这将导致一个巨大的,丑陋的段if语句.
对于那些没有使用过SFML的人:链接到sf :: Event类源代码
在尝试创建我的问题中概述的函数之后,我发现它无论如何都不起作用,因为你不能在C++中返回多个字符串,因此大多数事件都被忽略.
示例源(不起作用):
std::string getEvent()
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {window.close(); return "";}
else if (event.type == sf::Event::GainedFocus) {return "GainedFocus";}
else if (event.type == sf::Event::LostFocus) {return "LostFocus";}
else if (event.type == sf::Event::Resized) {return "Resized";}
else if (event.type == sf::Event::TextEntered)
{
if ((event.text.unicode < 128) && (event.text.unicode > 0)) {return "" + static_cast<char>(event.text.unicode);}
}
else if (event.type == sf::Event::KeyPressed)
{
//If else for …Run Code Online (Sandbox Code Playgroud) 在我的特定情况下,我有一个复杂的类(一类类的类),我想要暴露给脚本语言(又名Ruby).相反,直接传递那个复杂的类,有人给了我一个想法,就是像Ruby这样的脚本语言开放一些函数,这看起来更简单.我见过赖斯,但我见过的唯一例子是使用简单的函数来增加某些东西,而不是与类接口.
为简单起见,我有一个简单的类,包含我想要公开的函数:
class Foo
{
private:
//Integer Vector:
std::vector<int> fooVector;
public:
//Functions to expose to Ruby:
void pushBack(const int& newInt) {fooVector.push_back(newInt);}
int& getInt(const int& element) {return fooVector.at(element);}
};
Run Code Online (Sandbox Code Playgroud)
也:
我不想只是链接到SWIG的下载页面,或者是一篇文章解释如何用2010年编写的米饭来做这个,我想要一个可能有用的指南(我运气不好)还没)
藏汉:
我正在使用Linux(Ubuntu),但这是一个交叉兼容的程序,所以我必须能够在Windows和OS X上编译
编辑:
我知道存在共享库(dll和so文件),但我不知道我是否可以拥有一个依赖于包含类的.hpp文件的库.
g++ -lsfml-window -lsfml-graphics -lsfml-system main.cpp在示例SFML代码上运行,在Ubuntu,SFML 2.2和g ++ 4.8.2上运行时,出现一系列错误。我尝试从包管理器(libsfml-dev)重新安装SFML,但没有任何效果。
SFML代码示例:
#include <SFML/Graphics.hpp>
#include <string>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
/tmp/ccVG6GjG.o: In function `main':
main.cpp:(.text+0xf7): undefined reference to `sf::String::String(char const*, std::locale const&)'
main.cpp:(.text+0x115): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
main.cpp:(.text+0x148): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, …Run Code Online (Sandbox Code Playgroud) 如果我在 Python 中有这样的函数:
def multiply(a, b)
return a * b
Run Code Online (Sandbox Code Playgroud)
PyObject_CallObject如果我有两个以上的参数,我如何调用它何时会给我一个错误?从 C++ 调用函数可能有更好的方法,但我对 Python/C API 很陌生