Testing 具有图形输出的Lua测试仪?

Testing 具有图形输出的Lua测试仪?,testing,graph,lua,drawing,Testing,Graph,Lua,Drawing,我正在搜索一个应用程序或服务,在那里我可以用图形输出测试Lua代码。 类似于或,但不仅仅是基于文本的输出 很多游戏都使用lua编写脚本,其中大多数都是draw_circle()和draw_line()之类的函数。我需要一个工具,可以输出这样的2D图形函数的代码。 可以给我这样的代码结果: --should draw two circles and connect their centers with a line --draw_circle(x, y, radius, color) draw_c

我正在搜索一个应用程序或服务,在那里我可以用图形输出测试Lua代码。 类似于或,但不仅仅是基于文本的输出

很多游戏都使用lua编写脚本,其中大多数都是draw_circle()和draw_line()之类的函数。我需要一个工具,可以输出这样的2D图形函数的代码。 可以给我这样的代码结果:

--should draw two circles and connect their centers with a line
--draw_circle(x, y, radius, color)
draw_circle(300, 300, 100, 0xff0000)
draw_circle(600, 300, 100, 0x00ff00)
--draw_line(x1, y1, x2, y2, width, color)
draw_line(300, 300, 600, 300, 1, 0x0000ff)
有这样的事吗?
(用C或其他语言编写的东西也不错)

我不知道是否已经有了一些东西,但是在C应用程序中嵌入Lua并使用自定义函数对其进行扩展非常简单(如果您知道C),对于我建议的图形和

编辑

很抱歉,Linux不知道您在使用什么,而且SDL_gfx不支持线条宽度

apt get install libsdl-gfx1.2-dev liblua5.1-0-dev

生成文件:

CC = gcc
CFLAGS = -Wall -O2
CFLAGS += $(shell pkg-config SDL_gfx --cflags)
LIBS += $(shell pkg-config SDL_gfx --libs)
CFLAGS += $(shell pkg-config lua5.1 --cflags)
LIBS += $(shell pkg-config lua5.1 --libs)

all: test

test.o: test.c
    $(CC) $(CFLAGS) -c -o $@ $<

test: test.o
    $(CC) -o $@ $< $(LIBS)

.PHONY: clean
clean:
    -rm -f test *.o
CC=gcc
CFLAGS=-Wall-O2
CFLAGS+=$(外壳包装配置SDL\U gfx——CFLAGS)
LIBS+=$(外壳程序包配置SDL_gfx--LIBS)
CFLAGS+=$(外壳程序包配置lua5.1--CFLAGS)
LIBS+=$(shell包配置lua5.1--LIBS)
全部:测试
测试o:测试c
$(CC)$(CFLAGS)-c-o$@$<
测试:test.o
$(CC)-o$@$<$(LIBS)
.假冒:干净
清洁:
-rm-f测试*.o
测试c:

#include <SDL.h>
#include <SDL_gfxPrimitives.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#define lua_toUINT(L,i)       ((unsigned int)lua_tointeger(L,(i)))

static SDL_Surface *out;

/* draw_circle(x, y, radius, color) */
static int draw_circle(lua_State *L) {
    unsigned int x, y, r, color;
    x = lua_toUINT(L, 1);
    y = lua_toUINT(L, 2);
    r = lua_toUINT(L, 3);
    color = (lua_toUINT(L, 4) << 8) | 0xff;
    circleColor(out, x, y, r, color);
    return 0;
}

/* draw_line(x1, y1, x2, y2, width, color) */
static int draw_line(lua_State *L) {
    unsigned int x1, y1, x2, y2, color;
    x1 = lua_toUINT(L, 1);
    y1 = lua_toUINT(L, 2);
    x2 = lua_toUINT(L, 3);
    y2 = lua_toUINT(L, 4);
    /* width ignored SDL_gfx have not such thing */
    color = (lua_toUINT(L, 6) << 8) | 0xff;
    lineColor(out, x1, y1, x2, y2, color);
    return 0;
}

int main (int argc, char *argv[]) {
    SDL_Event event;
    int over = 0;
    lua_State *L;

    L = lua_open();
    luaL_openlibs(L);
    lua_register(L, "draw_circle", draw_circle);
    lua_register(L, "draw_line", draw_line);
    SDL_Init(SDL_INIT_VIDEO);
    out = SDL_SetVideoMode(640, 480, 0, 0);
    (void)luaL_dofile(L,"script.lua");
    SDL_UpdateRect(out, 0, 0, 0, 0);
    while (!over) {
        if (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT)
                over = 1;
        }
    }
    SDL_Quit();
    lua_close(L);
    return 0;
}
#包括
#包括
#包括
#包括
#包括
#定义lua_toUINT(L,i)((无符号int)lua_tointeger(L,(i)))
静态SDL_表面*out;
/*绘制圆(x、y、半径、颜色)*/
静态整数绘制圆(lua\U状态*L){
无符号整数x,y,r,颜色;
x=lua_toUINT(L,1);
y=lua_toUINT(L,2);
r=lua_toUINT(L,3);

color=(lua_toUINT(L,4)因此,我花了一些时间尝试让示例在Windows上运行,但所有解决方案都太复杂或/或需要太多的安装

相反,我们发现了一个非常好且功能强大的库,名为with ready

(我使用了
dynamic
/
Win32\u dll8
版本)

该库功能强大,可以输出到许多系统和多种格式(svg、pdf等),但我想输出到一个常见的窗口应用程序,因此需要另一个库,同样使用

(再次
动态
/
Win32 dll8

我必须将这两个库提取到同一个目录中(但我想Lua上有某种方法可以添加
.dll
的搜索路径)

在同一目录中还需要一个助手脚本

编辑

还有一个脚本可以为您的示例获得相同的输出:

app.lua:

require "iupcdaux"

dialog = iupcdaux.new_dialog(640, 480)
canvas = dialog[1]

function hex2rgb(hex)
    hex = string.format("%06x", hex)
    return cd.EncodeColor(tonumber("0x"..hex:sub(1,2)),
           tonumber("0x"..hex:sub(3,4)),
           tonumber("0x"..hex:sub(5,6)))
end

function draw_circle(x, y, r, rgb)
  canvas:LineWidth(1)
  canvas:Foreground(hex2rgb(rgb)) 
  canvas:Arc(x, y, r*2, r*2, 0, 360)
end

function draw_line(x1, y1, x2, y2, w, rgb)
  canvas:LineWidth(w)
  canvas:Foreground(hex2rgb(rgb))
  canvas:Line(x1, y1, x2, y2) 
end

function canvas:Draw(canvas)
  canvas:LineStyle(cd.CONTINUOUS) 
  dofile("script.lua")
end

dialog:show()
iup.MainLoop()
script.lua:

draw_circle(300, 300, 100, 0xff0000)
draw_circle(600, 300, 100, 0xff00)
draw_line(300, 300, 600, 300, 1, 0xff)
在这里,这个
app.lua
script查找与您的示例相同语法的脚本
script.lua

最小设置:

├── cd.dll
├── cdlua51.dll
├── app.lua
├── freetype6.dll
├── iupcdaux.lua
├── iupcd.dll
├── iup.dll
├── iuplua51.dll
├── iupluacd51.dll
├── lua5.1.dll
├── lua5.1.exe
├── Microsoft.VC80.CRT
│   ├── Microsoft.VC80.CRT.manifest
│   ├── msvcm80.dll
│   ├── msvcp80.dll
│   └── msvcr80.dll
├── script.lua
└── zlib1.dll

它可能很简单,但我不擅长C^^'我可以将代码更改为C来测试它,但我不认为我可以制作一个C应用程序并将其嵌入。.我正在编写一个简单的示例,以供大家参考,请稍候:)我使用windows,但我会设置一个虚拟机并测试它。唷,我真的不知道如何设置XD可能
cygwin
是一种简单的方法,但我不确定所有的库是否都可用,我稍后会尝试一下,然后让你知道。谢谢你的工作,但我正在搜索一些比在实际游戏中尝试更容易、更快的东西。但是设置所有的一切都结束了,改变代码,这将是更多的工作,不仅仅是开始游戏本身^^我不是一个Lua专家,但我认为你可以很容易地包装函数,以获得你想要的语法,只是使画布是一个全球性的,设置是3解压和1下载的助手脚本,比它看起来容易得多。好的,我会尝试它以后^^