【发布时间】:2016-05-26 03:24:04
【问题描述】:
我试图在我的应用程序中使用 lua,但是在尝试使用 lua_loadBuffer 加载脚本时,我收到一条错误消息。
LuaContext := lua_newstate(@Alloc, nil);
try
luaL_openlibs(LuaContext);
s := 'print("hi")';
lua_register(LuaContext, 'print', @print_func);
if luaL_loadbuffer(LuaContext, PChar(s), Length(s), PChar('sample1')) <> 0 then
begin
raise Exception.Create(lua_tostring(LuaContext, -1)); //<- I get the following error message here: [string "sample1"]:1: syntax error
end;
if lua_pcall(LuaContext, 0, 0, 0) <> 0 then
Exception.Create('');
except
Debugln('Error: ' + lua_tostring(LuaContext, -1));
end;
Afaik lua 代码是有效的,对吧? 只是一个“语法错误”的描述性不是很好,而且我对 lua 没有任何经验,我什至不知道在哪里寻找错误。
【问题讨论】:
-
试试
var s:AnsiString; -
@EgorSkriptunoff 谢谢,那行得通。你可能想发布一个答案,所以我可以接受。
-
Egor 主要做 cmets;答案有一个长度限制,他通常低于 ;)。随意发布并接受您自己的答案。
-
@PaulKulchenko - 有时我会打破这个传统 :-)
标签: lua pascal freepascal