luasandbox  1.4.0
Generic Lua sandbox for dynamic data analysis
luasandbox_serialize.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /** Lua sandbox serialization @file */
8 
9 #ifndef luasandbox_serialize_h_
10 #define luasandbox_serialize_h_
11 
12 #include <stdio.h>
13 
15 #include "luasandbox_output.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include "luasandbox/lua.h"
22 
23 /**
24  * Add a serialization function to the environment table. The environment table
25  * must be on the top of the stack. This function will receive the userdata,
26  * fully qualified variable name, and lsb_output_buffer struct as pointers on the
27  * Lua stack.
28  *
29  * lsb_output_buffer* output = (output_data*)lua_touserdata(lua, -1);
30  * const char *key = (const char*)lua_touserdata(lua, -2);
31  * ud_object* ud = (ud_object*)lua_touserdata(lua, -3);
32  *
33  * @param lua Pointer the Lua state.
34  * @param fp Function pointer to the serializer.
35  *
36  * @return lsb_err_value NULL on success error message on failure
37  */
38 LSB_EXPORT void
40 
41 /**
42  * Serializes a binary data to a Lua string.
43  *
44  * @param output Pointer the output buffer.
45  * @param src Pointer to the binary data.
46  * @param len Length in bytes of the data to output.
47  *
48  * @return lsb_err_value NULL on success error message on failure
49  */
51 lsb_serialize_binary(lsb_output_buffer *output, const void *src, size_t len);
52 
53 /**
54  * More efficient serialization of a double to a string
55  *
56  * @param output Pointer the output buffer.
57  * @param d Double value to convert to a string.
58  *
59  * @return lsb_err_value NULL on success error message on failure
60  */
62 lsb_serialize_double(lsb_output_buffer *output, double d);
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
68 #endif
const char * lsb_err_value
Definition: error.h:15
Lua sandbox output generation/retrieval functions.
LSB_EXPORT lsb_err_value lsb_serialize_binary(lsb_output_buffer *output, const void *src, size_t len)
Serializes a binary data to a Lua string.
LSB_EXPORT void lsb_add_serialize_function(lua_State *lua, lua_CFunction fp)
Add a serialization function to the environment table.
int(* lua_CFunction)(lua_State *L)
Definition: lua.h:52
struct lua_State lua_State
Definition: lua.h:50
Data stream output buffer.
LSB_EXPORT lsb_err_value lsb_serialize_double(lsb_output_buffer *output, double d)
More efficient serialization of a double to a string.
#define LSB_EXPORT
Definition: luasandbox.h:24