lua_run.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
30 #ifndef LUA_RUN_H
31 #define LUA_RUN_H
32 
33 #include <stdint.h>
34 
35 #include "lua.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
44 #define LUAR_LOAD_FLAG(n) (((uint16_t)1) << (n))
45 
50  LUAR_LOAD_O_BASE,
51  LUAR_LOAD_O_PACKAGE,
52  LUAR_LOAD_O_CORO,
53  LUAR_LOAD_O_TABLE,
54  LUAR_LOAD_O_IO,
55  LUAR_LOAD_O_OS,
56  LUAR_LOAD_O_STRING,
57  LUAR_LOAD_O_MATH,
58  LUAR_LOAD_O_UTF8,
59  LUAR_LOAD_O_DEBUG,
60  LUAR_LOAD_O_ALL,
61 };
62 
64 #define LUAR_LOAD_BASE LUAR_LOAD_FLAG(LUAR_LOAD_O_BASE)
65 
66 #define LUAR_LOAD_PACKAGE LUAR_LOAD_FLAG(LUAR_LOAD_O_PACKAGE)
67 
68 #define LUAR_LOAD_CORO LUAR_LOAD_FLAG(LUAR_LOAD_O_CORO)
69 
70 #define LUAR_LOAD_TABLE LUAR_LOAD_FLAG(LUAR_LOAD_O_TABLE)
71 
72 #define LUAR_LOAD_IO LUAR_LOAD_FLAG(LUAR_LOAD_O_IO)
73 
74 #define LUAR_LOAD_OS LUAR_LOAD_FLAG(LUAR_LOAD_O_OS)
75 
76 #define LUAR_LOAD_STRING LUAR_LOAD_FLAG(LUAR_LOAD_O_STRING)
77 
78 #define LUAR_LOAD_MATH LUAR_LOAD_FLAG(LUAR_LOAD_O_MATH)
79 
80 #define LUAR_LOAD_UTF8 LUAR_LOAD_FLAG(LUAR_LOAD_O_UTF8)
81 
82 #define LUAR_LOAD_DEBUG LUAR_LOAD_FLAG(LUAR_LOAD_O_DEBUG)
83 
84 /* TODO: maybe we can implement a "restricted base" package containing a subset
85  * of base that is safe. */
86 
87 #define LUAR_LOAD_ALL (0xFFFF)
88 #define LUAR_LOAD_NONE (0x0000)
91 enum LUAR_ERRORS {
92  LUAR_EXIT,
104 };
105 
109 extern const char *lua_riot_str_errors[];
110 
119 LUALIB_API const char *lua_riot_strerror(int errn);
120 
137 LUALIB_API lua_State *lua_riot_newstate(void *memory, size_t mem_size,
138  lua_CFunction panicf);
139 
146 #ifndef LUA_DEBUG
147  #define lua_riot_close lua_close
148 #else
149  #define lua_riot_close luaB_close
150 #endif /* LUA_DEBUG */
151 
173 LUALIB_API int lua_riot_openlibs(lua_State *L, uint16_t modmask);
174 
194 LUALIB_API int lua_riot_do_module(const char *modname, void *memory, size_t mem_size,
195  uint16_t modmask, int *retval);
196 
214 LUALIB_API int lua_riot_do_buffer(const uint8_t *buf, size_t buflen, void *memory,
215  size_t mem_size, uint16_t modmask, int *retval);
216 
217 #ifdef __cplusplus
218 extern "C" }
219 #endif
220 
223 #endif /* LUA_RUN_H */
lua_riot_newstate
LUALIB_API lua_State * lua_riot_newstate(void *memory, size_t mem_size, lua_CFunction panicf)
Initialize a lua state and set the panic handler.
lua_riot_strerror
const LUALIB_API char * lua_riot_strerror(int errn)
Return a string describing an error from LUAR_ERRORS.
lua_riot_do_buffer
LUALIB_API int lua_riot_do_buffer(const uint8_t *buf, size_t buflen, void *memory, size_t mem_size, uint16_t modmask, int *retval)
Initialize the interpreter and run a user supplied buffer in protected mode.
lua_riot_str_errors
const char * lua_riot_str_errors[]
Human-readable description of the errors.
LUAR_MEMORY_ERR
@ LUAR_MEMORY_ERR
Error in code execution.
Definition: lua_run.h:98
LUAR_LOAD_ORDER
LUAR_LOAD_ORDER
Order in which the builtin libraries are loaded.
Definition: lua_run.h:49
lua_riot_do_module
LUALIB_API int lua_riot_do_module(const char *modname, void *memory, size_t mem_size, uint16_t modmask, int *retval)
Initialize the interpreter and run a built-in module in protected mode.
LUAR_STARTUP_ERR
@ LUAR_STARTUP_ERR
The program exited without error.
Definition: lua_run.h:93
LUAR_RUNTIME_ERR
@ LUAR_RUNTIME_ERR
The Lua code failed to compile.
Definition: lua_run.h:97
LUAR_COMPILE_ERR
@ LUAR_COMPILE_ERR
The specified module could not be found.
Definition: lua_run.h:96
LUAR_NOMODULE
@ LUAR_NOMODULE
Error while loading libraries.
Definition: lua_run.h:95
LUAR_LOAD_ERR
@ LUAR_LOAD_ERR
Error setting up the interpreter.
Definition: lua_run.h:94
LUAR_INTERNAL_ERR
@ LUAR_INTERNAL_ERR
Lua could not allocate enough memory.
Definition: lua_run.h:99
lua_riot_openlibs
LUALIB_API int lua_riot_openlibs(lua_State *L, uint16_t modmask)
Open builtin libraries.