Add asynchronous model for mruby bindings
This commit is contained in:
		
							parent
							
								
									a234f2d5b2
								
							
						
					
					
						commit
						737d5add01
					
				
					 2 changed files with 38 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -258,6 +258,19 @@ runMrbFile(mrb_state *mrb, const char *filename)
 | 
			
		|||
	fclose(f);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static mrb_state * static_mrb;
 | 
			
		||||
static mrb_state * static_scriptmrb;
 | 
			
		||||
 | 
			
		||||
void __attribute__ ((optnone)) main_update_loop() {
 | 
			
		||||
	mrb_load_nstring_cxt(static_mrb, "main_update_loop", 16, NULL);
 | 
			
		||||
	if (static_mrb->exc) {
 | 
			
		||||
		printf("Execution Errored\n");
 | 
			
		||||
		mrb_close(static_scriptmrb);
 | 
			
		||||
		shState->texPool().disable();
 | 
			
		||||
		mrb_close(static_mrb);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -309,9 +322,6 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
 | 
			
		|||
 | 
			
		||||
	for (int i = 0; i < scriptCount; ++i)
 | 
			
		||||
	{
 | 
			
		||||
#ifdef __EMSCRIPTEN
 | 
			
		||||
		emscripten_sleep(10);
 | 
			
		||||
#endif
 | 
			
		||||
		mrb_value script = mrb_ary_entry(scriptArray, i);
 | 
			
		||||
 | 
			
		||||
		mrb_value scriptChksum = mrb_ary_entry(script, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -368,7 +378,23 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
 | 
			
		|||
			break;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	static_mrb = mrb;
 | 
			
		||||
	static_scriptmrb = scriptMrb;
 | 
			
		||||
 | 
			
		||||
#ifdef __EMSCRIPTEN__
 | 
			
		||||
	/* Use loop for emscripten */
 | 
			
		||||
	mrb_load_nstring_cxt(static_mrb, "main_update_loop", 16, NULL);
 | 
			
		||||
	emscripten_set_main_loop(main_update_loop, 0, 1);
 | 
			
		||||
	return;
 | 
			
		||||
#else
 | 
			
		||||
	while (true) {
 | 
			
		||||
		main_update_loop();
 | 
			
		||||
		SDL_Delay(20);
 | 
			
		||||
		if (static_mrb->exc)
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
	mrb_close(scriptMrb);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void mrbBindingExecute()
 | 
			
		||||
| 
						 | 
				
			
			@ -400,6 +426,7 @@ static void mrbBindingExecute()
 | 
			
		|||
	else
 | 
			
		||||
		runRMXPScripts(mrb, ctx);
 | 
			
		||||
 | 
			
		||||
#ifndef __EMSCRIPTEN__
 | 
			
		||||
	checkException(mrb);
 | 
			
		||||
 | 
			
		||||
	shState->rtData().rqTermAck.set();
 | 
			
		||||
| 
						 | 
				
			
			@ -407,6 +434,7 @@ static void mrbBindingExecute()
 | 
			
		|||
 | 
			
		||||
	mrbc_context_free(mrb, ctx);
 | 
			
		||||
	mrb_close(mrb);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void mrbBindingTerminate()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										7
									
								
								binding-mruby/run.xxd
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								binding-mruby/run.xxd
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
00000000: 5249 5445 3030 3034 5969 0000 0065 4d41  RITE0004Yi...eMA
 | 
			
		||||
00000010: 545a 3030 3030 4952 4550 0000 0047 3030  TZ0000IREP...G00
 | 
			
		||||
00000020: 3030 0000 003f 0001 0004 0000 0000 0004  00...?..........
 | 
			
		||||
00000030: 0080 0006 0100 003d 0080 00a0 0000 004a  .......=.......J
 | 
			
		||||
00000040: 0000 0001 0000 0b48 656c 6c6f 2057 6f72  .......Hello Wor
 | 
			
		||||
00000050: 6c64 0000 0001 0004 7075 7473 0045 4e44  ld......puts.END
 | 
			
		||||
00000060: 0000 0000 08                             .....
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue