Console

Output

The output multiline receives all the output generated by prints and errors. Also serves as a command history of the command line. When a command is executed by the command line, its strings appears preceded by the ">" character indicating that the command execution was started.

The interface toolkit limits the size of the text in the multiline in 32768 byes. When the output becomes full the oldest text is overwritten. When it reach near full capacity also becomes very slow, you can minimize this reducing even more the size of the output buffer.

The following functions can be called from Lua code to access the console output:

lcClearOutput()
lcEnterMessage(msg: string)
lcEnterCommandStr(cmd: string)

Print/Error

The Lua functions print and error are redefined to send the output text to the console. The print function can have more than one parameter, and prints tabs between them. Tables, functions and user data are not printed, instead the type is printed "<table>", "<function>", "<cfunction>", "<userdata>".

Command Line

The text written in the command line text box is executed when the user press <Enter>. The execution is NOT a simple dostring. When a command is entered we first try a getglobal on it, if it returns a valid object then we print its value, else when evaluate the expression to check if it has a return value, if any its value is printed after the dostring. But it is NOT a shell command line, for example the function "pwd" that show the name of the current directory, must be executed using "pwd()".

So I can write command like these:

x = 0
s = "bbb"
t = {4,5,6,{x="aaa"}}
t[1]=3
if x==nil then x = sin(0) else x = sin(10) end

and like these:

x  (where x is nil) Outputs: nil
s                   Outputs: "bbb"
3+5                 Outputs: 8
t[1]                Outputs: 4
sin(0)              Outputs: 0

If a command returns more than one value, all of them are printed:

--Take the example:
function f()
  return 1, "name", sin
end
-- When executed:

> f()
<1° return> = 1
<2° return> = "name"
<3° return> = <cfunction>

The command history can be accessed using the up and down keys. The <Esc> key clears the command line.

Check the functions lcListFunc and lcListVar description bellow to see how functions and variables are printed or in this case inspected.

The following function can be called from Lua code to execute a command as if it was executed from the command line:

lcEnterCommand(cmd: string)

Run File

Allows you to select a file for a "dofile". After selection the file is automatically executed. The current directory is changed to the file directory.

Initialization

To use the Console inside your application you just have to include the header "lconsole.h" and call the function luaConsoleCreate("parent", CloseFlag). Check the LUACMD.C file for an example. And do not forget to call utlCreateButtonImages once to initialize the toolbar images, and also luaConsoleKill and utlKillButtonImages after the program ends the message loop.


Functions

lcListFunc()

Lists all the global functions defined on the current state. C functions are marked with a "(C)" after the function name. Be careful using this function because it can be slow if a large number of functions are defined.

When you inspect a Lua function in the command line instead of just the function name, also the location of the function definition is printed:

myfunc = <function> (defined in the file "func.lua" at line 3)

-- or in the case it is inside of a string
lcListFunc = <function> (defined in a string at line 1)

- a C function
sin = <cfunction>

If the function is also a tag method then the print changes to:

Tgetglobal = <function> ("getglobal" tag method) [defined in the file "trace.lua" at line 16]

lcListVar()

Lists all the global variables defined on the current state. Be careful using this function because it can be slow if a large number of variables are defined.

When printing variables values, each type is printed differently:

1           -- integer number
1.5000      -- real number
"1"         -- string
"aaa"       -- string
nil         -- nil value

_OUTPUT = <userdata> (tag = -7)  -- user data

t =                -- table
{
  [1] = 4          -- integer number
  [2] = 5
  [3] = 6
  [4] = 
  {
    ["x"] = "aaa"  -- string
  }
}

Tables are printed up to depth level 5. If a table has more than 5 levels the 6 level has the string "{table too deep}" instead. This avoid an infinite loop in self referenced tables.

lcAbout()

Shows information about the version number and authors' name of the used libraries and the application. This function is executed when Lua Commander is started.

Internal Functions

The following functions appears when you execute the  lcListFunc function. They are for internal use only, do not use them directly.

lcHoldCaret, lcPrintFuncVar, lcPrintVar, lcPrintTable