function TVerySimpleLua.Print(L: Lua_State): Integer;
var
N, I: Integer;
S: MarshaledAString;
Sz: size_t;
Msg: String;
begin
Msg := '';
N := lua_gettop(L); //* number of arguments */
lua_getglobal(L, 'tostring');
for I := 1 to N do
begin
lua_pushvalue(L, -1); //* function to be called */
lua_pushvalue(L, i); //* value to print */
lua_call(L, 1, 1);
S := lua_tolstring(L, -1, @Sz); //* get result */
if S = NIL then
begin
Result := luaL_error(L, '"tostring" must return a string to "print"',[]);
Exit;
end;
if I > 1 then
Msg := Msg + #9;
// Msg := Msg + String(S); 把这句改成下面那句就行了
Msg := Msg + String(UTF8String(S));
lua_pop(L, 1); //* pop result */
end;
Result := 0;
DoPrint(Msg);
end;
VerySimple.Lua 2.0 print 中文乱码问题
最新推荐文章于 2024-08-28 09:19:34 发布