[Overview][Types][Classes][Procedures and functions] | Reference for unit 'pLua' (#pLua)

# plua_tostring

## Declaration

Source position: plua.pas line 18

`function plua_tostring(`
`L: Plua_State;`
`Index: Integer`
`):ansistring;`

## Arguments

`L` |  | PLua_State to work with.
`Index` |  | Stack index to convert/return.

## Function result

AnsiString representing the lua item on the stack at the index provided.

## Description

Converts the Lua value at the given acceptable index to a Pascal AnsiString. The Lua value must be a string or a number; otherwise, the function returns NULL. If the value is a number, then plua_tostring also changes the actual value in the stack to a string. (This change confuses lua_next when plua_tostring is applied to keys during a table traversal.)
Example:

    function lua_print(l : PLua_State) : integer; cdecl;
    var
      n, c : Integer;
      AString : AnsiString;
    begin
      result := 0;
      n := lua_gettop(L);
      AString := '';
      for c := 1 to n do
        AString := AString + plua_tostring(l, c);
      Write(AString);
    end;

## See also

lua.lua_tostring |  |