aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends/lua.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2020-03-08 12:13:38 +0100
committercbdev <cb@cbcdn.com>2020-03-08 12:13:38 +0100
commitf9829ae90d4017940047b561e412c6eb7f431adb (patch)
treec94f4bcb67bd4680343303cfef998999acb314ea /backends/lua.c
parentdde2cca435b2c314a08024825b1daffa6437b947 (diff)
downloadmidimonster-f9829ae90d4017940047b561e412c6eb7f431adb.tar.gz
midimonster-f9829ae90d4017940047b561e412c6eb7f431adb.tar.bz2
midimonster-f9829ae90d4017940047b561e412c6eb7f431adb.zip
Implement timestamp() callback for Lua
Diffstat (limited to 'backends/lua.c')
-rw-r--r--backends/lua.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/backends/lua.c b/backends/lua.c
index 955341a..9a8091e 100644
--- a/backends/lua.c
+++ b/backends/lua.c
@@ -75,7 +75,7 @@ static int lua_update_timerfd(){
size_t n = 0;
#ifdef MMBACKEND_LUA_TIMERFD
struct itimerspec timer_config = {
- 0
+ {0}
};
#endif
@@ -260,7 +260,7 @@ static int lua_callback_value(lua_State* interpreter, uint8_t input){
//find correct channel & return value
for(n = 0; n < data->channels; n++){
if(!strcmp(channel_name, data->channel_name[n])){
- lua_pushnumber(data->interpreter, (input) ? data->input[n] : data->output[n]);
+ lua_pushnumber(interpreter, (input) ? data->input[n] : data->output[n]);
return 1;
}
}
@@ -283,6 +283,11 @@ static int lua_callback_input_channel(lua_State* interpreter){
return 1;
}
+static int lua_callback_timestamp(lua_State* interpreter){
+ lua_pushnumber(interpreter, mm_timestamp());
+ return 1;
+}
+
static int lua_configure(char* option, char* value){
LOG("No backend configuration possible");
return 1;
@@ -326,6 +331,7 @@ static int lua_instance(instance* inst){
lua_register(data->interpreter, "input_value", lua_callback_input_value);
lua_register(data->interpreter, "output_value", lua_callback_output_value);
lua_register(data->interpreter, "input_channel", lua_callback_input_channel);
+ lua_register(data->interpreter, "timestamp", lua_callback_timestamp);
//store instance pointer to the lua state
lua_pushstring(data->interpreter, LUA_REGISTRY_KEY);
@@ -417,9 +423,6 @@ static int lua_handle(size_t num, managed_fd* fds){
return 1;
}
#else
- if(!last_timestamp){
- last_timestamp = mm_timestamp();
- }
delta = mm_timestamp() - last_timestamp;
last_timestamp = mm_timestamp();
#endif
@@ -458,6 +461,7 @@ static int lua_start(size_t n, instance** inst){
&& strcmp(data->channel_name[p], "input_value")
&& strcmp(data->channel_name[p], "output_value")
&& strcmp(data->channel_name[p], "input_channel")
+ && strcmp(data->channel_name[p], "timestamp")
&& strcmp(data->channel_name[p], "interval")){
lua_getglobal(data->interpreter, data->channel_name[p]);
data->reference[p] = luaL_ref(data->interpreter, LUA_REGISTRYINDEX);
@@ -474,6 +478,8 @@ static int lua_start(size_t n, instance** inst){
if(mm_manage_fd(timer_fd, BACKEND_NAME, 1, NULL)){
return 1;
}
+ #else
+ last_timestamp = mm_timestamp();
#endif
return 0;
}