diff --git a/libraries/AP_Scripting/examples/param_get_set_test.lua b/libraries/AP_Scripting/examples/param_get_set_test.lua index 6a93d077451..85ba3857456 100644 --- a/libraries/AP_Scripting/examples/param_get_set_test.lua +++ b/libraries/AP_Scripting/examples/param_get_set_test.lua @@ -1,6 +1,19 @@ -- This script is a test of param set and get local count = 0 +-- for fast param acess it is better to get a param object, +-- this saves the code searching for the param by name every time +local VM_I_Count = Parameter() +if not VM_I_Count:init('SCR_VM_I_COUNT') then + gcs:send_text(6, 'get SCR_VM_I_COUNT failed') +end + +-- returns null if param cant be found +local fake_param = Parameter() +if not fake_param:init('FAKE_PARAM') then + gcs:send_text(6, 'get FAKE_PARAM failed') +end + function update() -- this is the loop which periodically runs -- get and print all the scripting parameters @@ -39,6 +52,18 @@ function update() -- this is the loop which periodically runs gcs:send_text(6, 'LUA: get SCR_HEAP_SIZE failed') end + + -- increment the VM I count by one using direct accsess method + local VM_count = VM_I_Count:get() + if VM_count then + gcs:send_text(6, string.format('LUA: SCR_VM_I_COUNT: %i',VM_count)) + if not VM_I_Count:set( VM_count + 1) then + gcs:send_text(6, string.format('LUA: failed to set SCR_VM_I_COUNT')) + end + else + gcs:send_text(6, 'LUA: read SCR_VM_I_COUNT failed') + end + count = count + 1; diff --git a/libraries/AP_Scripting/generator/description/bindings.desc b/libraries/AP_Scripting/generator/description/bindings.desc index 7cf22d553b8..4adab510b3d 100644 --- a/libraries/AP_Scripting/generator/description/bindings.desc +++ b/libraries/AP_Scripting/generator/description/bindings.desc @@ -248,6 +248,13 @@ singleton AP_Param method get boolean string float'Null singleton AP_Param method set boolean string float -FLT_MAX FLT_MAX singleton AP_Param method set_and_save boolean string float -FLT_MAX FLT_MAX +include AP_Scripting/AP_Scripting_helpers.h +userdata Parameter method init boolean string +userdata Parameter method get boolean float'Null +userdata Parameter method set boolean float -FLT_MAX FLT_MAX +userdata Parameter method set_and_save boolean float -FLT_MAX FLT_MAX + + include AP_Mission/AP_Mission.h singleton AP_Mission alias mission singleton AP_Mission scheduler-semaphore