mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-11 10:28:29 -04:00
AP_Scripting: Add a one arg variant of uint32_t, and expose table unpack
This commit is contained in:
parent
37288b585c
commit
4eaf4b72ad
@ -4,19 +4,6 @@
|
|||||||
|
|
||||||
extern const AP_HAL::HAL& hal;
|
extern const AP_HAL::HAL& hal;
|
||||||
|
|
||||||
int new_uint32_t(lua_State *L) {
|
|
||||||
luaL_checkstack(L, 2, "Out of stack");
|
|
||||||
*static_cast<uint32_t *>(lua_newuserdata(L, sizeof(uint32_t))) = 0; // allocated memory is already zerod, no need to manipulate this
|
|
||||||
luaL_getmetatable(L, "uint32_t");
|
|
||||||
lua_setmetatable(L, -2);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t * check_uint32_t(lua_State *L, int arg) {
|
|
||||||
void *data = luaL_checkudata(L, arg, "uint32_t");
|
|
||||||
return static_cast<uint32_t *>(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t coerce_to_uint32_t(lua_State *L, int arg) {
|
static uint32_t coerce_to_uint32_t(lua_State *L, int arg) {
|
||||||
{ // userdata
|
{ // userdata
|
||||||
const uint32_t * ud = static_cast<uint32_t *>(luaL_testudata(L, arg, "uint32_t"));
|
const uint32_t * ud = static_cast<uint32_t *>(luaL_testudata(L, arg, "uint32_t"));
|
||||||
@ -47,6 +34,25 @@ static uint32_t coerce_to_uint32_t(lua_State *L, int arg) {
|
|||||||
return luaL_argerror(L, arg, "Unable to coerce to uint32_t");
|
return luaL_argerror(L, arg, "Unable to coerce to uint32_t");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int new_uint32_t(lua_State *L) {
|
||||||
|
luaL_checkstack(L, 2, "Out of stack");
|
||||||
|
|
||||||
|
const int args = lua_gettop(L);
|
||||||
|
if (args > 1) {
|
||||||
|
return luaL_argerror(L, args, "too many arguments");
|
||||||
|
}
|
||||||
|
|
||||||
|
*static_cast<uint32_t *>(lua_newuserdata(L, sizeof(uint32_t))) = (args == 1) ? coerce_to_uint32_t(L, 1) : 0;
|
||||||
|
luaL_getmetatable(L, "uint32_t");
|
||||||
|
lua_setmetatable(L, -2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t * check_uint32_t(lua_State *L, int arg) {
|
||||||
|
void *data = luaL_checkudata(L, arg, "uint32_t");
|
||||||
|
return static_cast<uint32_t *>(data);
|
||||||
|
}
|
||||||
|
|
||||||
#define UINT32_T_BOX_OP(name, sym) \
|
#define UINT32_T_BOX_OP(name, sym) \
|
||||||
static int uint32_t___##name(lua_State *L) { \
|
static int uint32_t___##name(lua_State *L) { \
|
||||||
const int args = lua_gettop(L); \
|
const int args = lua_gettop(L); \
|
||||||
|
@ -25,7 +25,7 @@ function get_sandbox_env ()
|
|||||||
rad = math.rad, random = math.random, sin = math.sin, sinh = math.sinh,
|
rad = math.rad, random = math.random, sin = math.sin, sinh = math.sinh,
|
||||||
sqrt = math.sqrt, tan = math.tan, tanh = math.tanh },
|
sqrt = math.sqrt, tan = math.tan, tanh = math.tanh },
|
||||||
table = { insert = table.insert, maxn = table.maxn, remove = table.remove,
|
table = { insert = table.insert, maxn = table.maxn, remove = table.remove,
|
||||||
sort = table.sort },
|
sort = table.sort, unpack = table.unpack },
|
||||||
utf8 = { char = utf8.char, charpattern = utf8.charpattern, codes = utf8.codes,
|
utf8 = { char = utf8.char, charpattern = utf8.charpattern, codes = utf8.codes,
|
||||||
codepoint = utf8.codepoint, len = utf8.len, offsets = utf8.offsets},
|
codepoint = utf8.codepoint, len = utf8.len, offsets = utf8.offsets},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user