-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.h
More file actions
60 lines (50 loc) · 1.57 KB
/
script.h
File metadata and controls
60 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef LIBGLITCH_SCRIPT_H
#define LIBGLITCH_SCRIPT_H
#include <luajit-2.1/lualib.h>
#include <luajit-2.1/lauxlib.h>
#include <goimg/goimg.h>
// Represents a parameter for a script.
typedef struct horizon_Param {
enum {
HORIZON_PARAM_INT,
HORIZON_PARAM_DOUBLE,
HORIZON_PARAM_STRING,
} kind;
const char *key;
union {
int k_int;
double k_double;
char *k_string;
} value;
} horizon_Param;
// Represents a list of parameters for a script.
typedef struct horizon_Params {
size_t len;
horizon_Param *list;
} horizon_Params;
// Represents a new lua script to glitch an image with.
typedef struct horizon_Script {
lua_State *L;
} horizon_Script;
// Error handler for scripts.
typedef struct horizon_ErrorCtx {
void *data;
void (*fn)(void *data, const char *error);
} horizon_ErrorCtx;
// Compiles a new script from a reader.
extern int horizon_ScriptCompile(horizon_Script *restrict script, void *src, rfun_t rf);
// Compiles a new script from a reader. Errors are reported with `ctx`.
extern int horizon_ScriptCompileCtx(
horizon_ErrorCtx *restrict ctx,
horizon_Script *restrict script,
void *src, rfun_t rf);
// Compiles a new script from a reader. Errors are reported with `ctx`.
// This version includes script parameters.
extern int horizon_ScriptCompileCtxParams(
horizon_Params *restrict params,
horizon_ErrorCtx *restrict ctx,
horizon_Script *restrict script,
void *src, rfun_t rf);
// Deallocates a script.
extern void horizon_ScriptClose(horizon_Script *restrict script);
#endif