luasandbox  1.4.0
Generic Lua sandbox for dynamic data analysis
Functions
luasandbox_output.h File Reference

Lua sandbox output generation/retrieval functions. More...

#include <stdio.h>
#include "luasandbox.h"
#include "luasandbox/lua.h"
Include dependency graph for luasandbox_output.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

LSB_EXPORT void lsb_add_output_function (lua_State *lua, lua_CFunction fp)
 Add a output function to the environment table. More...
 
LSB_EXPORT lua_CFunction lsb_get_output_function (lua_State *lua, int index)
 Utility function to retrieve a user data output function. More...
 
LSB_EXPORT void lsb_add_zero_copy_function (lua_State *lua, lua_CFunction fp)
 Add a zero copy function to the environment table. More...
 
LSB_EXPORT lua_CFunction lsb_get_zero_copy_function (lua_State *lua, int index)
 Utility function to retrieve a user data zero copy function. More...
 
LSB_EXPORT void lsb_output (lsb_lua_sandbox *lsb, int start, int end, int append)
 Write an array of variables on the Lua stack to the output buffer. More...
 
LSB_EXPORT void lsb_output_coroutine (lsb_lua_sandbox *lsb, lua_State *lua, int start, int end, int append)
 Write an array of variables on the Lua stack to the output buffer. More...
 
LSB_EXPORT const char * lsb_get_output (lsb_lua_sandbox *lsb, size_t *len)
 Retrieve the data in the output buffer and reset the buffer. More...
 

Detailed Description

Lua sandbox output generation/retrieval functions.

Definition in file luasandbox_output.h.

Function Documentation

LSB_EXPORT void lsb_add_output_function ( lua_State lua,
lua_CFunction  fp 
)

Add a output function to the environment table.

The environment table must be on the top of the stack. This function will receive the userdata and lsb_output_buffer struct as pointers on the Lua stack.

lsb_output_buffer* output = (output_data*)lua_touserdata(lua, -1); ud_object* ud = (ud_object*)lua_touserdata(lua, -2);

Parameters
luaPointer the Lua state.
fpFunction pointer to the outputter.
Returns
int Zero on success, non-zero on failure.
LSB_EXPORT void lsb_add_zero_copy_function ( lua_State lua,
lua_CFunction  fp 
)

Add a zero copy function to the environment table.

The environment table must be on the top of the stack. This function will receive the userdata as a pointer on the Lua stack.

ud_object* ud = (ud_object*)lua_touserdata(lua, -1);

Parameters
luaPointer the Lua state.
fpFunction pointer to the zero copy function.
Returns
int Number of segments (pointer and length for each)
LSB_EXPORT const char* lsb_get_output ( lsb_lua_sandbox lsb,
size_t *  len 
)

Retrieve the data in the output buffer and reset the buffer.

The returned output string will remain valid until additional sandbox output is performed. The output should be copied if the application needs to hold onto it.

Parameters
lsbPointer to the sandbox.
lenIf len is not NULL, it will be set to the length of the string.
Returns
const char* Pointer to the output buffer.
LSB_EXPORT lua_CFunction lsb_get_output_function ( lua_State lua,
int  index 
)

Utility function to retrieve a user data output function.

Parameters
lua
index
Returns
lua_CFunction
LSB_EXPORT lua_CFunction lsb_get_zero_copy_function ( lua_State lua,
int  index 
)

Utility function to retrieve a user data zero copy function.

Parameters
lua
index
Returns
lua_CFunction
LSB_EXPORT void lsb_output ( lsb_lua_sandbox lsb,
int  start,
int  end,
int  append 
)

Write an array of variables on the Lua stack to the output buffer.

Parameters
lsbPointer to the sandbox.
startLua stack index of first variable.
endLua stack index of the last variable.
append0 to overwrite the output buffer, 1 to append the output to it
LSB_EXPORT void lsb_output_coroutine ( lsb_lua_sandbox lsb,
lua_State lua,
int  start,
int  end,
int  append 
)

Write an array of variables on the Lua stack to the output buffer.

After adding support for coroutines we need an extra variable to specify the correct Lua state.

Parameters
lsbPointer to the sandbox.
luaPointer the Lua state
startLua stack index of first variable.
endLua stack index of the last variable.
append0 to overwrite the output buffer, 1 to append the output to it