Skip to content

Commit

Permalink
AP_Scripting: add basic print
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 authored and tridge committed Oct 4, 2023
1 parent 020807a commit a068569
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libraries/AP_Scripting/docs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ function micros() end
---@return number|nil -- command param 4
function mission_receive() end

-- Print text, if MAVLink is available the value will be sent with debug severity
-- If no MAVLink the value will be sent over can
-- equivalent to gcs:send_text(7, text) or periph:can_printf(text)
---@param text string|number|integer
function print(text) end

-- data flash logging to SD card
---@class logger
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ userdata uint32_t manual tofloat uint32_t_tofloat 0

global manual dirlist lua_dirlist 1
global manual remove lua_removefile 1
global manual print lua_print 1

singleton mavlink depends HAL_GCS_ENABLED
singleton mavlink manual init lua_mavlink_init 2
Expand Down
10 changes: 10 additions & 0 deletions libraries/AP_Scripting/lua_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,14 @@ int lua_get_current_ref()
return scripting->get_current_ref();
}

// Simple print to GCS or over CAN
int lua_print(lua_State *L) {
// Only support a single argument
binding_argcheck(L, 1);

GCS_SEND_TEXT(MAV_SEVERITY_DEBUG, "%s", luaL_checkstring(L, 1));

return 0;
}

#endif // AP_SCRIPTING_ENABLED
1 change: 1 addition & 0 deletions libraries/AP_Scripting/lua_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ int lua_mavlink_receive_chan(lua_State *L);
int lua_mavlink_register_rx_msgid(lua_State *L);
int lua_mavlink_send_chan(lua_State *L);
int lua_mavlink_block_command(lua_State *L);
int lua_print(lua_State *L);

0 comments on commit a068569

Please sign in to comment.