1 //Lua Game Engine Framework
10 #include "funcs_input.h"
11 #include "funcs_video.h"
12 #include "funcs_sound.h"
13 #include "funcs_font.h"
17 int main(int argc
, char *argv
[]){
20 lua_State
*L
= luaL_newstate();
24 SDL_Init(SDL_INIT_EVERYTHING
);
32 //load up configuration file and create screen surface
33 screen
= load_config(L
);
35 cerr
<< "Error: Cannot create video surface. \n";
41 //register functions with lua
42 lua_pushcfunction(L
, l_getimage
);
43 lua_setglobal(L
, "get_image");
45 lua_pushcfunction(L
, l_releaseimage
);
46 lua_setglobal(L
, "release_image");
48 lua_pushcfunction(L
, l_flip
);
49 lua_setglobal(L
, "update_screen");
51 lua_pushcfunction(L
, l_blit
);
52 lua_setglobal(L
, "blit");
54 lua_pushcfunction(L
, l_blitframe
);
55 lua_setglobal(L
, "blit_frame");
57 lua_pushcfunction(L
, l_mouse_state
);
58 lua_setglobal(L
, "mouse_state");
60 lua_pushcfunction(L
, l_show_cursor
);
61 lua_setglobal(L
, "show_cursor");
63 lua_pushcfunction(L
, l_fill_screen
);
64 lua_setglobal(L
, "fill_screen");
66 lua_pushcfunction(L
, l_delete_image
);
67 lua_setglobal(L
, "delete_image");
69 lua_pushcfunction(L
, l_rotzoom
);
70 lua_setglobal(L
, "rotzoom");
72 lua_pushcfunction(L
, l_playsample
);
73 lua_setglobal(L
, "play_sample");
75 lua_pushcfunction(L
, l_playmusic
);
76 lua_setglobal(L
, "play_music");
78 lua_pushcfunction(L
, l_stopmusic
);
79 lua_setglobal(L
, "stop_music");
81 lua_pushcfunction(L
, l_load_font
);
82 lua_setglobal(L
, "load_font");
84 lua_pushcfunction(L
, l_close_font
);
85 lua_setglobal(L
, "unload_font");
87 lua_pushcfunction(L
, l_font_string_metrics
);
88 lua_setglobal(L
, "rendered_string_size");
90 lua_pushcfunction(L
, l_render_string
);
91 lua_setglobal(L
, "render_string");
93 lua_pushcfunction(L
, l_get_event
);
94 lua_setglobal(L
, "get_event");
96 lua_pushcfunction(L
, l_getticks
);
97 lua_setglobal(L
, "get_ticks");
99 lua_pushcfunction(L
, l_delay
);
100 lua_setglobal(L
, "delay");
102 lua_pushcfunction(L
, l_num_joysticks
);
103 lua_setglobal(L
, "num_joysticks");
105 //force joystick event handling on
106 SDL_JoystickEventState(SDL_ENABLE
);
108 //open up all available joysticks
109 std::list
<SDL_Joystick
*> joystick_list
;
110 for(int i
=0; i
< SDL_NumJoysticks(); i
++){
111 joystick_list
.push_back(SDL_JoystickOpen(i
));
112 std::cout
<< "Opened Joystick: " << SDL_JoystickName(i
) << std::endl
;
115 //load up the main script into the lua environment
116 //and make it all happen
117 int error_main
= luaL_loadfile(L
, "base/init.lua") ||
118 lua_pcall(L
, 0, 0, 0);
120 if ( error_main
) { // die a horrible death b/c we can't run without that file
121 cerr
<< lua_tostring(L
, -1) << "\n";
124 //close any opened joysticks
125 for(std::list
<SDL_Joystick
*>::iterator it
=joystick_list
.begin(); it
!= joystick_list
.end(); it
++){
126 SDL_JoystickClose(*it
);
131 SoundEngine::close();
138 //close any opened joysticks
139 for(std::list
<SDL_Joystick
*>::iterator it
=joystick_list
.begin(); it
!= joystick_list
.end(); it
++){
140 SDL_JoystickClose(*it
);
148 SoundEngine::close();
150 //cleanup image store