加载lua脚本时出现语法错误

时间:2016-05-25 08:45:15

标签: lua pascal freepascal

我试图在我的应用程序中使用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代码是有效的,对吗? 只是一个&#34;语法错误&#34;不是很具描述性,而且我对lua没有任何影响,我甚至不知道在哪里寻找错误。

1 个答案:

答案 0 :(得分:1)

Lua无法使用UTF-16字符串 为确保您的数据使用1字节代码页进行编码,请使用AnsiStringPAnsiChar代替String和PChar。

相关问题