Skip to content

Commit

Permalink
Merge pull request #442 from monome/reset_lvm
Browse files Browse the repository at this point in the history
Reset lvm
  • Loading branch information
tehn authored Jun 28, 2018
2 parents 27b2050 + 99ea64d commit 557df05
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions matron/src/event_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ typedef enum {
EVENT_STARTUP_READY_OK,
// crone startup timeout event
EVENT_STARTUP_READY_TIMEOUT,
// reset the lua state
EVENT_RESET_LVM,
// quit the event loop
EVENT_QUIT,
} event_t;
Expand Down
3 changes: 3 additions & 0 deletions matron/src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ static void handle_event(union event_data *ev) {
case EVENT_STARTUP_READY_TIMEOUT:
w_handle_startup_ready_timeout();
break;
case EVENT_RESET_LVM:
w_reset_lvm();
break;
case EVENT_QUIT:
quit = true;
break;
Expand Down
30 changes: 29 additions & 1 deletion matron/src/weaver.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ static int _restart_audio(lua_State *l);
// soundfile inspection
static int _sound_file_inspect(lua_State *l);

// reset LVM
static int _reset_lvm(lua_State *l);

// boilerplate: push a function to the stack, from field in global 'norns'
static inline void
_push_norns_func(const char *field, const char *func) {
Expand Down Expand Up @@ -290,6 +293,9 @@ void w_init(void) {
// returns channels, frames, samplerate
lua_register(lvm, "sound_file_inspect", &_sound_file_inspect);

// reset LVM
lua_register(lvm, "_reset_lvm", &_reset_lvm);

// run system init code
char *config = getenv("NORNS_CONFIG");
char *home = getenv("HOME");
Expand All @@ -308,16 +314,38 @@ void w_init(void) {
// run startup code
// audio backend should be running
void w_startup(void) {
fprintf(stderr, "running startup\n");
lua_getglobal(lvm, "startup");
l_report(lvm, l_docall(lvm, 0, 0));
}

void w_deinit(void) {
// FIXME: lua is leaking memory. doesn't really matter
fprintf(stderr, "shutting down lua vm\n");
lua_close(lvm);
}

void w_reset_lvm() {
w_deinit();
w_init();
w_startup();
}


//----------------------------------
//---- static definitions
//
int _reset_lvm(lua_State *l) {
if (lua_gettop(l) != 0) {
return luaL_error(l, "wrong number of arguments");
}
lua_settop(l, 0);

// do this through the event loop, not from inside a lua pcall
event_post( event_data_new(EVENT_RESET_LVM) );

return 0;
}


/***
* screen: update (flip buffer)
Expand Down
3 changes: 3 additions & 0 deletions matron/src/weaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ extern void w_run_code(const char *code);
// call it only from the main thread
extern void w_handle_exec_code_line(char *line);

// reset the lua state machine
extern void w_reset_lvm();

//-------------------------
//---- c -> lua glue

Expand Down

0 comments on commit 557df05

Please sign in to comment.