whiskers 0.4.5
RP2350 BadUSB Tool
Loading...
Searching...
No Matches
wlua.h File Reference

Detailed Description

Basic functions to setup the lua functionality.

Author
zane

These functions only initialize and start lua as a whole on the device. All functionality that is built in is within wlua.c, wlua_fops.c, and wlua_usb.c.

To find the list of all the exposed lua functions see lua_functions.h

#include "../../hal/file.h"
#include "../../hal/flash.h"
#include "../../hal/standard.h"
#include "../../lua/lua.h"
#include "../../lua/lualib.h"
#include "../../lua/lauxlib.h"
#include "wlua_fops.h"
#include "wlua_usb.h"
#include "../usb/wusb.h"
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define WLUA_MAX_INPUT_SIZE   (1024 * 32) - 1
 Max buffer size for the input into lua. If the file size is bigger than this, it will split it into chunks for the interpreter. Note this can have adverse affects if it splits in the middle of a control statement as the lua interpreter will lose context (blame lua not me!).
#define WLUA_MAX_FLASH_SIZE   1024 * 1024
 Max size of lua script to be saved in flash. Note that this must be aligned to multiples of FLASH_SECTOR_SIZE.
#define WLUA_FLASH_SECTORS   (uint32_t)(WLUA_MAX_FLASH_SIZE/FLASH_SECTOR_SIZE)
 Number of sectors to be set aside for the lua script.

Functions

void start_lua (lua_State **lua)
 Sets up the initial lua state and registers all the exposed functions for user use in lua code.
bool run_lua_from_file (const char *path, lua_State *lua)
 Runs lua from a file.
void stop_lua (lua_State *lua)
 Stops the lua interpreter and frees it's resources.
bool run_lua_from_flash (lua_State *lua)
 Runs the saved lua program from flash.
bool save_lua_to_flash ()
 Saves the active payload script (payload.lua) to flash memory.

Function Documentation

◆ run_lua_from_file()

bool run_lua_from_file ( const char * path,
lua_State * lua )

Runs lua from a file.

Parameters
*pathPath to file.
*lualua_State that has been initialized by start_lua();
Returns
True on success, and false if the file cannot be opened.

◆ run_lua_from_flash()

bool run_lua_from_flash ( lua_State * lua)

Runs the saved lua program from flash.

Parameters
*lualua_State that has been initialized by start_lua();

Typically only runs if no payload.lua can be found on the SD card, or the SD card is not there.

Returns
True on success, and false if no program is found/can be ran.

◆ save_lua_to_flash()

bool save_lua_to_flash ( )

Saves the active payload script (payload.lua) to flash memory.

This function saves the entire raw form of the payload.lua file to flash memory. By default there is about one megabyte of room for this, so you should never run out of room.

Try to avoid saving the payload file a lot, as repeated writes (it takes a lot, in excess of around 10k, but it's still possible) can damage the flash and overtime make it un-usable.

Returns
True on success/False on error.

◆ start_lua()

void start_lua ( lua_State ** lua)

Sets up the initial lua state and registers all the exposed functions for user use in lua code.

Parameters
**luaPointer to an empty lua_State struct pointer. This function initializes this and this must be kept and re-used in all the functions.

◆ stop_lua()

void stop_lua ( lua_State * lua)

Stops the lua interpreter and frees it's resources.

Parameters
*luaActive lua instance to be stopped and freed.