Loading...
Searching...
No Matches
lua_run.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Freie Universität Berlin
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
29
30#include <stdint.h>
31
32#include "lua.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
41#define LUAR_LOAD_FLAG(n) (((uint16_t)1) << (n))
42
47 LUAR_LOAD_O_BASE,
48 LUAR_LOAD_O_PACKAGE,
49 LUAR_LOAD_O_CORO,
50 LUAR_LOAD_O_TABLE,
51 LUAR_LOAD_O_IO,
52 LUAR_LOAD_O_OS,
53 LUAR_LOAD_O_STRING,
54 LUAR_LOAD_O_MATH,
55 LUAR_LOAD_O_UTF8,
56 LUAR_LOAD_O_DEBUG,
57 LUAR_LOAD_O_ALL,
58};
59
61#define LUAR_LOAD_BASE LUAR_LOAD_FLAG(LUAR_LOAD_O_BASE)
63#define LUAR_LOAD_PACKAGE LUAR_LOAD_FLAG(LUAR_LOAD_O_PACKAGE)
65#define LUAR_LOAD_CORO LUAR_LOAD_FLAG(LUAR_LOAD_O_CORO)
67#define LUAR_LOAD_TABLE LUAR_LOAD_FLAG(LUAR_LOAD_O_TABLE)
69#define LUAR_LOAD_IO LUAR_LOAD_FLAG(LUAR_LOAD_O_IO)
71#define LUAR_LOAD_OS LUAR_LOAD_FLAG(LUAR_LOAD_O_OS)
73#define LUAR_LOAD_STRING LUAR_LOAD_FLAG(LUAR_LOAD_O_STRING)
75#define LUAR_LOAD_MATH LUAR_LOAD_FLAG(LUAR_LOAD_O_MATH)
77#define LUAR_LOAD_UTF8 LUAR_LOAD_FLAG(LUAR_LOAD_O_UTF8)
79#define LUAR_LOAD_DEBUG LUAR_LOAD_FLAG(LUAR_LOAD_O_DEBUG)
80
81/* TODO: maybe we can implement a "restricted base" package containing a subset
82 * of base that is safe. */
83
84#define LUAR_LOAD_ALL (0xFFFF)
85#define LUAR_LOAD_NONE (0x0000)
86
102
106extern const char *lua_riot_str_errors[];
107
116LUALIB_API const char *lua_riot_strerror(int errn);
117
134LUALIB_API lua_State *lua_riot_newstate(void *memory, size_t mem_size,
135 lua_CFunction panicf);
136
143#ifndef LUA_DEBUG
144 #define lua_riot_close lua_close
145#else
146 #define lua_riot_close luaB_close
147#endif /* LUA_DEBUG */
148
170LUALIB_API int lua_riot_openlibs(lua_State *L, uint16_t modmask);
171
191LUALIB_API int lua_riot_do_module(const char *modname, void *memory, size_t mem_size,
192 uint16_t modmask, int *retval);
193
211LUALIB_API int lua_riot_do_buffer(const uint8_t *buf, size_t buflen, void *memory,
212 size_t mem_size, uint16_t modmask, int *retval);
213
214#ifdef __cplusplus
215extern "C" }
216#endif
217
LUAR_ERRORS
Errors that can be raised when running lua code.
Definition lua_run.h:88
@ LUAR_MEMORY_ERR
Error in code execution.
Definition lua_run.h:95
@ LUAR_NOMODULE
Error while loading libraries.
Definition lua_run.h:92
@ LUAR_INTERNAL_ERR
Lua could not allocate enough memory.
Definition lua_run.h:96
@ LUAR_RUNTIME_ERR
The Lua code failed to compile.
Definition lua_run.h:94
@ LUAR_COMPILE_ERR
The specified module could not be found.
Definition lua_run.h:93
@ LUAR_LOAD_ERR
Error setting up the interpreter.
Definition lua_run.h:91
@ LUAR_STARTUP_ERR
The program exited without error.
Definition lua_run.h:90
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:46
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.