| 1 |
/* WirePlumber |
| 2 |
* |
| 3 |
* Copyright © 2020 Collabora Ltd. |
| 4 |
* @author George Kiagiadakis <[email protected]> |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: MIT |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef __WPLUA_H__ |
| 10 |
#define __WPLUA_H__ |
| 11 |
|
| 12 |
#include <wp/wp.h> |
| 13 |
|
| 14 |
#include <lua.h> |
| 15 |
#include <lauxlib.h> |
| 16 |
#include <lualib.h> |
| 17 |
|
| 18 |
G_BEGIN_DECLS |
| 19 |
|
| 20 |
/** |
| 21 |
* WP_DOMAIN_LUA: |
| 22 |
* |
| 23 |
* @brief A <a href="https://developer.gnome.org/glib/stable/glib-Error-Reporting.html#GError"> |
| 24 |
* GError</a> domain for errors that occurred within the context of the |
| 25 |
* WirePlumber lua library. |
| 26 |
*/ |
| 27 |
#define WP_DOMAIN_LUA (wp_domain_lua_quark ()) |
| 28 |
GQuark wp_domain_lua_quark (void); |
| 29 |
|
| 30 |
/** |
| 31 |
* WpLuaError: |
| 32 |
* |
| 33 |
* @brief |
| 34 |
* @em WP_LUA_ERROR_COMPILATION: a compilation error, i.e. invalid Lua code |
| 35 |
* @em WP_LUA_ERROR_RUNTIME: a runtime error, i.e. misbehaving Lua code |
| 36 |
* |
| 37 |
* Error codes that can appear in a |
| 38 |
* <a href="https://developer.gnome.org/glib/stable/glib-Error-Reporting.html#GError"> |
| 39 |
* GError</a> when the error domain is %WP_DOMAIN_LUA |
| 40 |
*/ |
| 41 |
typedef enum { |
| 42 |
WP_LUA_ERROR_COMPILATION, |
| 43 |
WP_LUA_ERROR_RUNTIME, |
| 44 |
} WpLuaError; |
| 45 |
|
| 46 |
typedef enum { |
| 47 |
WP_LUA_SANDBOX_ISOLATE_ENV = 1, |
| 48 |
} WpLuaSandboxFlags; |
| 49 |
|
| 50 |
lua_State * wplua_new (void); |
| 51 |
lua_State * wplua_ref (lua_State *L); |
| 52 |
void wplua_unref (lua_State * L); |
| 53 |
|
| 54 |
void wplua_enable_sandbox (lua_State * L, WpLuaSandboxFlags flags); |
| 55 |
int wplua_push_sandbox (lua_State * L); |
| 56 |
|
| 57 |
void wplua_register_type_methods (lua_State * L, GType type, |
| 58 |
lua_CFunction constructor, const luaL_Reg * methods); |
| 59 |
|
| 60 |
GType wplua_gvalue_userdata_type (lua_State *L, int idx); |
| 61 |
|
| 62 |
/* push -> transfer full; get -> transfer none */ |
| 63 |
void wplua_pushobject (lua_State * L, gpointer object); |
| 64 |
gpointer wplua_toobject (lua_State *L, int idx); |
| 65 |
gpointer wplua_checkobject (lua_State *L, int idx, GType type); |
| 66 |
gboolean wplua_isobject (lua_State *L, int idx, GType type); |
| 67 |
|
| 68 |
/* push -> transfer full; get -> transfer none */ |
| 69 |
void wplua_pushboxed (lua_State * L, GType type, gpointer object); |
| 70 |
gpointer wplua_toboxed (lua_State *L, int idx); |
| 71 |
gpointer wplua_checkboxed (lua_State *L, int idx, GType type); |
| 72 |
gboolean wplua_isboxed (lua_State *L, int idx, GType type); |
| 73 |
|
| 74 |
/* transfer floating */ |
| 75 |
GClosure * wplua_checkclosure (lua_State *L, int idx); |
| 76 |
GClosure * wplua_function_to_closure (lua_State *L, int idx); |
| 77 |
|
| 78 |
void wplua_enum_to_lua (lua_State *L, gint enum_val, GType enum_type); |
| 79 |
gint wplua_lua_to_enum (lua_State *L, int idx, GType enum_type); |
| 80 |
|
| 81 |
void wplua_lua_to_gvalue (lua_State *L, int idx, GValue *v); |
| 82 |
int wplua_gvalue_to_lua (lua_State *L, const GValue *v); |
| 83 |
|
| 84 |
GVariant * wplua_lua_to_gvariant (lua_State *L, int idx); |
| 85 |
void wplua_gvariant_to_lua (lua_State *L, GVariant *p); |
| 86 |
|
| 87 |
WpProperties * wplua_table_to_properties (lua_State *L, int idx); |
| 88 |
void wplua_properties_to_table (lua_State *L, WpProperties *p); |
| 89 |
|
| 90 |
gboolean wplua_load_buffer (lua_State * L, const gchar *buf, gsize size, |
| 91 |
GError **error); |
| 92 |
gboolean wplua_load_uri (lua_State * L, const gchar *uri, GError **error); |
| 93 |
gboolean wplua_load_path (lua_State * L, const gchar *path, GError **error); |
| 94 |
|
| 95 |
gboolean wplua_pcall (lua_State * L, int nargs, int nres, GError **error); |
| 96 |
|
| 97 |
G_DEFINE_AUTOPTR_CLEANUP_FUNC(lua_State, wplua_unref) |
| 98 |
|
| 99 |
G_END_DECLS |
| 100 |
|
| 101 |
#endif |