小编Col*_*Two的帖子

使用Lua C Api从索引获取数组值

我有这个数组:

a = {{4,2,2,6}, {2,1,1,2}}
Run Code Online (Sandbox Code Playgroud)

如何从该数组中检索索引到C程序?

例如:

a[1] -- {4,2,2,6}
a[1][2] -- 2
Run Code Online (Sandbox Code Playgroud)

c lua lua-api lua-table

3
推荐指数
1
解决办法
1549
查看次数

在 LuaJ 中获取打印调用

我正在编写一个 Java 程序,它使用 Lua 脚本来确定要输出到程序的某些区域的内容。目前,我的代码如下所示:

Globals globals = JsePlatform.standardGlobals();
LuaValue chunk = globals.loadfile(dir.getAbsolutePath() + "/" + name);
chunk.call();
String output = chunk.tojstring();
Run Code Online (Sandbox Code Playgroud)

问题是调用似乎从 Lua 脚本tojstring()返回值。return这很好,但我需要接听print电话,因为这就是屏幕上显示的内容。截至目前,print调用直接发送到控制台(打印到控制台),并且我无法找到检索这些打印调用的方法。

我尝试过深入研究文档,但收效甚微。如果需要的话将从 LuaJ 进行更改。

java lua luaj

3
推荐指数
1
解决办法
763
查看次数

疯狂的闪烁窗口OpenGL GLFW

我已完成以下视频 https://www.youtube.com/watch?v=shpdt6hCsT4 但是,我的hello world窗口如下所示:http: //s1303.photobucket.com/user/eskimo___/media/screenshot_124_zps890ae561.jpg .html 我出错的任何想法?我使用osx yosemite和最新的GLFW欢呼声


按照要求:

我的项目文件夹由3个文件组成,这些文件是使用终端进程的一部分:

  1. main.cpp(C++源代码)
  2. Makefile文件(TXT)
  3. 测试(Unix可执行文件)

我使用自制软件在我的mac上设置了glfw3库.

Main.cpp是在图片窗口中产生不良效果的,它由网站GLFW文档部分的示例代码组成:

include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* …
Run Code Online (Sandbox Code Playgroud)

opengl glfw

3
推荐指数
1
解决办法
2051
查看次数

无法定义关联数组类型:opEquals不存在

我不能使用非基本类型作为关联数组的键; 尝试这样做会导致我定义AA的行上出现以下错误:

Error: AA key type MyString does not have 'bool opEquals(ref const MyString) const
Run Code Online (Sandbox Code Playgroud)

我在第一次使用type时发现了这个CollisionHandler[Tuple!(TypeInfo, TypeInfo)],它CollisionHandler是函数指针类型的别名.

但是,即使" 关联数组文档"页面下的"使用结构或联合作为键类型"标题中的示例代码也会失败并出现相同的错误:

import std.string;

struct MyString
{
    string str;

    size_t toHash() const @safe pure nothrow
    {
        size_t hash;
        foreach (char c; str)
        hash = (hash * 9) + c;
        return hash;
    }
    // opEquals defined here?
    bool opEquals(ref const MyString s) const @safe pure nothrow
    {
        return std.string.cmp(this.str, s.str) == 0;
    }
}

int[MyString] foo; // errors here …
Run Code Online (Sandbox Code Playgroud)

d

3
推荐指数
1
解决办法
77
查看次数

C ++如何使函数指针指向类方法

我在制作指向类方法的函数指针时遇到麻烦。我做了一个指向非类方法的函数指针,它工作正常。

int foo(){
    return 5;
}

 int main()
{
    int (*pointer)() = foo;

    std::cout << pointer();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我试图将其应用为使类中的实例变量成为函数指针。

这是头文件。它声明了变量方法将指向的私有方法Print。

class Game
{

public:

    Game();

private:

    void Print();

    void (method)( void );

};
Run Code Online (Sandbox Code Playgroud)

Game构造函数尝试将指针方法分配给Print方法的地址。编译时,该行出现错误,提示“错误:必须调用对非静态成员函数的引用;”。我不知道那是什么意思 什么是实现此目的的正确方法?

Game::Game( void )
{

    method = &Game::Print;

}

void Game::Print(){
    std::cout << "PRINT";
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers function-pointers

3
推荐指数
2
解决办法
8419
查看次数

匹配文档注释的宏规则

有没有办法匹配 Rust 中的文档注释macro_rules

我有一个宏,可以为一堆 C 常量生成枚举,从而bindgen创建:

macro_rules! id_enum {
    ( enum $name:ident: $typ:ty { $( $enum_name:ident => $value:expr ),* , } ) => { ... }
}
Run Code Online (Sandbox Code Playgroud)

我想用文档注释(注释///)来注释每个宏,但这要求我的宏与文档注释匹配。那可能吗?

rust rust-macros

3
推荐指数
1
解决办法
1473
查看次数

如何避免Haskell中的重复函数调用

如何避免此Haskell命令中的重复x

ccheck :: Balance -> Integer
ccheck b     | x >= 1200    = x - 7
             | otherwise    = x
               where x = account b
Run Code Online (Sandbox Code Playgroud)

haskell

2
推荐指数
1
解决办法
105
查看次数

Lua中的":"是什么意思

我是Lua的新手,我从事过项目工作,我有一个问题,不知道":"我没有在手册中找到它,例如如何解释这段代码:

res:template{
        main = 'functionform.html',
        functionjs = '_functionform.js',
        functionform = '_functionform.html'
    }
Run Code Online (Sandbox Code Playgroud)

lua

2
推荐指数
2
解决办法
1239
查看次数

Lua中匿名函数的类型是什么?

在Lua参考手册中,它说每个值都有一个类型,可能是本地,全局,表字段类型之一.我的问题是Lua中匿名函数的类型是什么?匿名函数有什么生命周期?我只是举个例子.

local co = coroutine.create( function () print "hi" end )

print(coroutine.status(co))
Run Code Online (Sandbox Code Playgroud)

lua

2
推荐指数
1
解决办法
346
查看次数

如何从命令行重新索引Postgres 9.1.3

我在我管理的Postgres数据库中的几个表上进行了一系列删除和更新.有人建议在一系列删除之后安排一个reindex作为10分钟下一步更新无限冻结的解决方案(随机地进行).DOS指令提供了这样的信息:

Usage:
  reindexdb [OPTION]... [DBNAME]

Options:
  -a, --all                 reindex all databases
  -d, --dbname=DBNAME       database to reindex
  -e, --echo                show the commands being sent to the server
  -i, --index=INDEX         recreate specific index only
  -q, --quiet               don't write any messages
  -s, --system              reindex system catalogs
  -t, --table=TABLE         reindex specific table only
  --help                    show this help, then exit
  --version                 output version information, then exit

Connection options:
  -h, --host=HOSTNAME       database server host or socket directory
  -p, --port=PORT           database server port
  -U, --username=USERNAME   user name …
Run Code Online (Sandbox Code Playgroud)

postgresql reindex postgresql-9.1

2
推荐指数
1
解决办法
4216
查看次数