MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / lua_new_Parameter

Function lua_new_Parameter

libraries/AP_Scripting/AP_Scripting_helpers.cpp:11–38  ·  view source on GitHub ↗

Custom lua constructor with optional param name

Source from the content-addressed store, hash-verified

9
10// Custom lua constructor with optional param name
11int lua_new_Parameter(lua_State *L) {
12
13 const int args = lua_gettop(L);
14 if (args > 1) {
15 return luaL_argerror(L, args, "too many arguments");
16 }
17 const char * name = nullptr;
18 if (args == 1) {
19 name = luaL_checkstring(L, 1);
20 }
21
22 // This chunk is the same as the auto generated constructor
23 void *ud = lua_newuserdata(L, sizeof(Parameter));
24 new (ud) Parameter();
25 luaL_getmetatable(L, "Parameter");
26 lua_setmetatable(L, -2);
27
28 if (args == 0) {
29 // no arguments, nothing to do
30 return 1;
31 }
32
33 if (!static_cast<Parameter*>(ud)->init(name)) {
34 return luaL_error(L, "No parameter: %s", name);
35 }
36
37 return 1;
38}
39
40// init by name
41bool Parameter::init(const char *name)

Callers

nothing calls this directly

Calls 6

lua_gettopFunction · 0.85
luaL_argerrorFunction · 0.85
lua_newuserdataFunction · 0.85
lua_setmetatableFunction · 0.85
luaL_errorFunction · 0.85
initMethod · 0.45

Tested by

no test coverage detected