lua_console.c 1.5 KB
Newer Older
1
2
3
4
5
6
7
8
/***
 Functions for writing data to the console
 
 @author Magic Lantern Team
 @copyright 2014
 @license GPL
 @module console
 */
9
10
11
12
13
14

#include <dryos.h>
#include <string.h>
#include <console.h>
#include "lua_common.h"

15
16
17
18
/***
 Show the console
 @function show
 */
19
20
21
22
23
24
static int luaCB_console_show(lua_State * L)
{
    console_show();
    return 0;
}

25
26
27
28
/***
 Hide the console
 @function hide
 */
29
30
31
32
33
34
static int luaCB_console_hide(lua_State * L)
{
    console_hide();
    return 0;
}

a1ex's avatar
a1ex committed
35
36
37
38
39
40
41
42
43
44
/***
 Clear the console contents
 @function clear
 */
static int luaCB_console_clear(lua_State * L)
{
    console_clear();
    return 0;
}

45
46
47
48
49
/***
 Write some text to the console
 @tparam string text the text to write
 @function write
 */
50
51
static int luaCB_console_write(lua_State * L)
{
52
    if(lua_isstring(L, 1)) printf("%s",lua_tostring(L, 1));
53
54
55
    return 0;
}

alex@thinkpad's avatar
alex@thinkpad committed
56
57
58
59
60
61
62
63
64
65
66
67
68
static int luaCB_console_index(lua_State * L)
{
    LUA_PARAM_STRING_OPTIONAL(key, 2, "");
    /// Whether or not the console is displayed.
    // @tfield bool visible
    if(!strcmp(key, "visible"))
    {
        extern int console_visible;
        lua_pushboolean(L, console_visible);
    }
    else lua_rawget(L, 1);
    return 1;
}
69
70
static int luaCB_console_newindex(lua_State * L) { lua_rawset(L, 1); return 0; }

71
72
73
74
75
76

static const char * lua_console_fields[] =
{
    NULL
};

77
78
79
80
static const luaL_Reg consolelib[] =
{
    { "show", luaCB_console_show },
    { "hide", luaCB_console_hide },
a1ex's avatar
a1ex committed
81
    { "clear", luaCB_console_clear },
82
83
84
85
    { "write", luaCB_console_write },
    { NULL, NULL }
};

a1ex's avatar
a1ex committed
86
LUA_LIB(console)