/*
* c8-lua: c8ui apps and live tiles written in Lua.
*
* The runner (main.c) loads a script, which says what it is with c8.app
* or c8.provider; ui.c is the widgets, draw.c what a list item or a
* canvas draws with, sys.c everything under the UI (timers, HTTP, JSON,
* commands, kept settings, tiles).
*/
#ifndef C8LUA_H
#define C8LUA_H
#include <stdbool.h>
#include <glib.h>
#include <lua.h>
#include <lauxlib.h>
#include <c8ui/c8ui.h>
#include <c8ui/c8ui-wayland.h>
/* main.c */
extern lua_State *c8l; // the one state; everything runs on the main loop
extern struct c8ui_app *c8l_app; // NULL before startup and for providers
/* Calls the function under nargs arguments, errors to stderr with where
* they happened; false when it failed (nothing is left on the stack then,
* else nresults) */
bool c8l_call(lua_State *L, int nargs, int nresults);
/* A Lua function kept for a callback from C that has no widget */
int c8l_ref(lua_State *L, int index); // LUA_NOREF for nil
void c8l_unref(lua_State *L, int ref);
bool c8l_push_ref(lua_State *L, int ref); // false: there is none
/* 0xRRGGBB from a number or "#rrggbb" */
uint32_t c8l_color(lua_State *L, int index, uint32_t fallback);
/* Fields of the table at index, with fallbacks */
const char *c8l_field_str(lua_State *L, int index, const char *key,
const char *fallback);
double c8l_field_num(lua_State *L, int index, const char *key,
double fallback);
bool c8l_field_bool(lua_State *L, int index, const char *key, bool fallback);
/* The strings of the table at index (or of its field key, when not
* NULL), NULL-terminated; g_strfreev it */
char **c8l_strings(lua_State *L, int index, const char *key, int *count);
/* ui.c */
void c8l_ui_open(lua_State *L); // adds to the c8 table on top
/* The widget of the userdata at index: NULL when it's gone (destroyed),
* an error when it never was one */
struct c8ui_widget *c8l_widget(lua_State *L, int index);
/* draw.c */
void c8l_draw_open(lua_State *L);
/* Pushes what a draw function draws with; c8l_draw_end makes it useless
* once the draw is over (the cairo context is only good that long) */
void c8l_draw_begin(lua_State *L, cairo_t *cr, struct c8ui_widget *w);
void c8l_draw_end(lua_State *L, int index);
cairo_surface_t *c8l_image(lua_State *L, int index); // NULL: not one
struct c8ui_icon *c8l_icon(const char *name); // kept by name; may be NULL
void c8l_push_event(lua_State *L, const struct c8ui_event *ev);
/* sys.c */
void c8l_sys_open(lua_State *L);
/* Whether the script made itself a tile provider (c8.provider) */
bool c8l_provider_started(void);
#endif