2020-12-11 17:07:20 +02:00
|
|
|
/* WirePlumber
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2020 Collabora Ltd.
|
|
|
|
|
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __WPLUA_H__
|
|
|
|
|
#define __WPLUA_H__
|
|
|
|
|
|
2020-12-22 11:33:35 +02:00
|
|
|
#include <wp/wp.h>
|
2020-12-11 17:07:20 +02:00
|
|
|
|
|
|
|
|
#include <lua.h>
|
|
|
|
|
#include <lauxlib.h>
|
|
|
|
|
#include <lualib.h>
|
|
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
2020-12-15 18:36:14 +02:00
|
|
|
/**
|
|
|
|
|
* WP_DOMAIN_LUA:
|
|
|
|
|
*
|
2021-05-13 17:54:58 +03:00
|
|
|
* @brief A <a href="https://developer.gnome.org/glib/stable/glib-Error-Reporting.html#GError">
|
|
|
|
|
* GError</a> domain for errors that occurred within the context of the
|
2020-12-15 18:36:14 +02:00
|
|
|
* WirePlumber lua library.
|
|
|
|
|
*/
|
|
|
|
|
#define WP_DOMAIN_LUA (wp_domain_lua_quark ())
|
|
|
|
|
GQuark wp_domain_lua_quark (void);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WpLuaError:
|
|
|
|
|
*
|
2021-05-13 17:54:58 +03:00
|
|
|
* @brief
|
|
|
|
|
* @em WP_LUA_ERROR_COMPILATION: a compilation error, i.e. invalid Lua code
|
|
|
|
|
* @em WP_LUA_ERROR_RUNTIME: a runtime error, i.e. misbehaving Lua code
|
|
|
|
|
*
|
|
|
|
|
* Error codes that can appear in a
|
|
|
|
|
* <a href="https://developer.gnome.org/glib/stable/glib-Error-Reporting.html#GError">
|
|
|
|
|
* GError</a> when the error domain is %WP_DOMAIN_LUA
|
2020-12-15 18:36:14 +02:00
|
|
|
*/
|
|
|
|
|
typedef enum {
|
|
|
|
|
WP_LUA_ERROR_COMPILATION,
|
|
|
|
|
WP_LUA_ERROR_RUNTIME,
|
|
|
|
|
} WpLuaError;
|
|
|
|
|
|
2021-02-01 16:14:34 +02:00
|
|
|
typedef enum {
|
|
|
|
|
WP_LUA_SANDBOX_MINIMAL_STD,
|
|
|
|
|
WP_LUA_SANDBOX_ISOLATE_ENV,
|
|
|
|
|
} WpLuaSandboxFlags;
|
2020-12-15 18:36:14 +02:00
|
|
|
|
2020-12-11 17:07:20 +02:00
|
|
|
lua_State * wplua_new (void);
|
|
|
|
|
void wplua_free (lua_State * L);
|
|
|
|
|
|
2021-02-01 16:14:34 +02:00
|
|
|
void wplua_enable_sandbox (lua_State * L, WpLuaSandboxFlags flags);
|
2022-03-30 18:22:21 +03:00
|
|
|
int wplua_push_sandbox (lua_State * L);
|
2020-12-15 18:28:28 +02:00
|
|
|
|
2020-12-11 17:07:20 +02:00
|
|
|
void wplua_register_type_methods (lua_State * L, GType type,
|
|
|
|
|
lua_CFunction constructor, const luaL_Reg * methods);
|
|
|
|
|
|
2021-06-02 13:13:20 +03:00
|
|
|
GType wplua_gvalue_userdata_type (lua_State *L, int idx);
|
|
|
|
|
|
2020-12-11 17:07:20 +02:00
|
|
|
/* push -> transfer full; get -> transfer none */
|
|
|
|
|
void wplua_pushobject (lua_State * L, gpointer object);
|
|
|
|
|
gpointer wplua_toobject (lua_State *L, int idx);
|
|
|
|
|
gpointer wplua_checkobject (lua_State *L, int idx, GType type);
|
2020-12-16 23:12:41 +02:00
|
|
|
gboolean wplua_isobject (lua_State *L, int idx, GType type);
|
2020-12-11 17:07:20 +02:00
|
|
|
|
|
|
|
|
/* push -> transfer full; get -> transfer none */
|
|
|
|
|
void wplua_pushboxed (lua_State * L, GType type, gpointer object);
|
|
|
|
|
gpointer wplua_toboxed (lua_State *L, int idx);
|
|
|
|
|
gpointer wplua_checkboxed (lua_State *L, int idx, GType type);
|
2020-12-16 23:12:41 +02:00
|
|
|
gboolean wplua_isboxed (lua_State *L, int idx, GType type);
|
2020-12-11 17:07:20 +02:00
|
|
|
|
|
|
|
|
/* transfer floating */
|
2021-06-10 14:40:08 +03:00
|
|
|
GClosure * wplua_checkclosure (lua_State *L, int idx);
|
2020-12-11 17:07:20 +02:00
|
|
|
GClosure * wplua_function_to_closure (lua_State *L, int idx);
|
2021-06-30 19:31:59 +03:00
|
|
|
|
|
|
|
|
void wplua_enum_to_lua (lua_State *L, gint enum_val, GType enum_type);
|
|
|
|
|
gint wplua_lua_to_enum (lua_State *L, int idx, GType enum_type);
|
|
|
|
|
|
2020-12-11 17:07:20 +02:00
|
|
|
void wplua_lua_to_gvalue (lua_State *L, int idx, GValue *v);
|
|
|
|
|
int wplua_gvalue_to_lua (lua_State *L, const GValue *v);
|
|
|
|
|
|
2021-02-13 12:42:36 +02:00
|
|
|
GVariant * wplua_lua_to_gvariant (lua_State *L, int idx);
|
|
|
|
|
void wplua_gvariant_to_lua (lua_State *L, GVariant *p);
|
|
|
|
|
|
2020-12-22 11:33:35 +02:00
|
|
|
WpProperties * wplua_table_to_properties (lua_State *L, int idx);
|
|
|
|
|
void wplua_properties_to_table (lua_State *L, WpProperties *p);
|
|
|
|
|
|
2020-12-11 17:07:20 +02:00
|
|
|
gboolean wplua_load_buffer (lua_State * L, const gchar *buf, gsize size,
|
|
|
|
|
GError **error);
|
2022-03-30 18:22:21 +03:00
|
|
|
gboolean wplua_load_uri (lua_State * L, const gchar *uri, GError **error);
|
|
|
|
|
gboolean wplua_load_path (lua_State * L, const gchar *path, GError **error);
|
|
|
|
|
|
|
|
|
|
gboolean wplua_pcall (lua_State * L, int nargs, int nres, GError **error);
|
2020-12-11 17:07:20 +02:00
|
|
|
|
2021-02-01 16:17:18 +02:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(lua_State, wplua_free)
|
|
|
|
|
|
2020-12-11 17:07:20 +02:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
|
|
#endif
|