Loading...
Searching...
No Matches
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
38extern "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)
66#define LUAR_LOAD_PACKAGE LUAR_LOAD_FLAG(LUAR_LOAD_O_PACKAGE)
68#define LUAR_LOAD_CORO LUAR_LOAD_FLAG(LUAR_LOAD_O_CORO)
70#define LUAR_LOAD_TABLE LUAR_LOAD_FLAG(LUAR_LOAD_O_TABLE)
72#define LUAR_LOAD_IO LUAR_LOAD_FLAG(LUAR_LOAD_O_IO)
74#define LUAR_LOAD_OS LUAR_LOAD_FLAG(LUAR_LOAD_O_OS)
76#define LUAR_LOAD_STRING LUAR_LOAD_FLAG(LUAR_LOAD_O_STRING)
78#define LUAR_LOAD_MATH LUAR_LOAD_FLAG(LUAR_LOAD_O_MATH)
80#define LUAR_LOAD_UTF8 LUAR_LOAD_FLAG(LUAR_LOAD_O_UTF8)
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)
105
109extern const char *lua_riot_str_errors[];
110
119LUALIB_API const char *lua_riot_strerror(int errn);
120
137LUALIB_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
173LUALIB_API int lua_riot_openlibs(lua_State *L, uint16_t modmask);
174
194LUALIB_API int lua_riot_do_module(const char *modname, void *memory, size_t mem_size,
195 uint16_t modmask, int *retval);
196
214LUALIB_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
218extern "C" }
219#endif
220
223#endif /* LUA_RUN_H */
LUAR_ERRORS
Errors that can be raised when running lua code.
Definition lua_run.h:91
@ LUAR_MEMORY_ERR
Error in code execution.
Definition lua_run.h:98
@ LUAR_NOMODULE
Error while loading libraries.
Definition lua_run.h:95
@ LUAR_INTERNAL_ERR
Lua could not allocate enough memory.
Definition lua_run.h:99
@ LUAR_RUNTIME_ERR
The Lua code failed to compile.
Definition lua_run.h:97
@ LUAR_COMPILE_ERR
The specified module could not be found.
Definition lua_run.h:96
@ LUAR_LOAD_ERR
Error setting up the interpreter.
Definition lua_run.h:94
@ LUAR_STARTUP_ERR
The program exited without error.
Definition lua_run.h:93
LUALIB_API const char * lua_riot_strerror(int errn)
Return a string describing an error from LUAR_ERRORS.
LUAR_LOAD_ORDER
Order in which the builtin libraries are loaded.
Definition lua_run.h:49
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.
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.
LUALIB_API int lua_riot_openlibs(lua_State *L, uint16_t modmask)
Open builtin libraries.
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.
const char * lua_riot_str_errors[]
Human-readable description of the errors.