@@ -295,8 +295,10 @@ def transpile(self, code: str, lang: str = "c") -> str:
295295 '' ,
296296 '#include <stdio.h>' ,
297297 '#include <string.h>' ,
298+ '#include <SDL.h>' , # Include SDL for windowing
299+ '' ,
300+ # Declare global string variable
298301 'char str[256] = "";' ,
299- '#include <SDL.h>' ,
300302 ''
301303 ]
302304 self .global_vars .clear ()
@@ -310,6 +312,9 @@ def transpile(self, code: str, lang: str = "c") -> str:
310312 self .indent_level = 1
311313 self .block_stack .clear ()
312314 self .vars .clear ()
315+ window_width = 640
316+ window_height = 480
317+ window_title = "BScript Window"
313318
314319 i = 0
315320 while i < len (lines ):
@@ -551,28 +556,41 @@ def transpile(self, code: str, lang: str = "c") -> str:
551556 i += 1
552557 continue
553558
554- # Window
559+ # windowSize command
560+ m = re .match (r'windowSize\s+(\d+)\s*,\s*(\d+);' , line )
561+ if m :
562+ window_width = int (m .group (1 ))
563+ window_height = int (m .group (2 ))
564+ i += 1
565+ continue
566+
567+ # windowTitle command
568+ m = re .match (r'windowTitle\s+"([^"]*)";' , line )
569+ if m :
570+ window_title = m .group (1 )
571+ i += 1
572+ continue
573+
574+ # window command
555575 if line == 'window;' :
556576 if windowed :
557577 raise Exception ("Window already created, cannot create another" )
558- continue
559-
560578 windowed = True
579+
561580 sdl_code = [
562581 "int main(int argc, char* argv[]) {" ,
563582 " if (SDL_Init(SDL_INIT_VIDEO) != 0) {" ,
564583 " printf(\" SDL_Init Error: %s\\ n\" , SDL_GetError());" ,
565584 " return 1;" ,
566585 " }" ,
567- " SDL_Window* window = SDL_CreateWindow(\" BScript Window \" ," ,
586+ f " SDL_Window* window = SDL_CreateWindow(\" { window_title } \" ," ,
568587 " SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED," ,
569- " 640, 480 , SDL_WINDOW_SHOWN);" ,
588+ f " { window_width } , { window_height } , SDL_WINDOW_SHOWN);" ,
570589 " if (!window) {" ,
571590 " printf(\" SDL_CreateWindow Error: %s\\ n\" , SDL_GetError());" ,
572591 " SDL_Quit();" ,
573592 " return 1;" ,
574593 " }" ,
575-
576594 " SDL_Event e;" ,
577595 " int running = 1;" ,
578596 " while (running) {" ,
@@ -583,7 +601,6 @@ def transpile(self, code: str, lang: str = "c") -> str:
583601 " }" ,
584602 " SDL_Delay(16);" ,
585603 " }" ,
586-
587604 " SDL_DestroyWindow(window);" ,
588605 " SDL_Quit();"
589606 ]
0 commit comments