Changeset 79 for UI/ui_lua.cpp
- Timestamp:
- 11/03/09 03:50:41 (4 years ago)
- File:
-
- 1 edited
-
UI/ui_lua.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
UI/ui_lua.cpp
r74 r79 13 13 #include "ui_window.h" 14 14 #include "ui_button.h" 15 #include "ui_picture.h" 15 16 16 17 void UI_Lua::RegisterUI(lua_State *luaVM){ … … 20 21 {"newButton", &UI_Lua::newButton}, 21 22 {"newLabel", &UI_Lua::newLabel}, 23 {"newPicture", &UI_Lua::newPicture}, 24 {"add", &UI_Lua::add}, 22 25 {"close", &UI_Lua::close}, 23 {"add", &UI_Lua::add}, 26 {"rotatePicture", &UI_Lua::rotatePicture}, 27 {"setText", &UI_Lua::setText}, 24 28 {NULL, NULL} 25 29 }; … … 113 117 } 114 118 119 int UI_Lua::newPicture(lua_State *luaVM){ 120 int n = lua_gettop(luaVM); // Number of arguments 121 if (n != 6) 122 return luaL_error(luaVM, "Got %d arguments expected 6 (class, x, y, w, h, caption )", n); 123 124 double x = luaL_checknumber (luaVM, 2); 125 double y = luaL_checknumber (luaVM, 3); 126 double w = luaL_checknumber (luaVM, 4); 127 double h = luaL_checknumber (luaVM, 5); 128 string filename = luaL_checkstring (luaVM, 6); 129 130 // Allocate memory for a pointer to object 131 Picture **pic= (Picture**)lua_newuserdata(luaVM, sizeof(Picture*)); 132 *pic = new Picture(x,y,w,h,filename); 133 134 // Note: We're not putting this Label anywhere! 135 // Lua will have to do that for us. 136 // This may be a bad idea (memory leaks from bad lua scripts) 137 138 return 1; 139 } 140 115 141 int UI_Lua::add(lua_State *luaVM){ 116 142 int n = lua_gettop(luaVM); // Number of arguments … … 124 150 return 0; 125 151 } 152 153 int UI_Lua::rotatePicture(lua_State *luaVM){ 154 int n = lua_gettop(luaVM); // Number of arguments 155 if (n != 2) 156 return luaL_error(luaVM, "Got %d arguments expected 2 (self, angle )", n); 157 158 Picture **pic= (Picture**)lua_touserdata(luaVM,1); 159 double angle = luaL_checknumber (luaVM, 2); 160 (*pic)->Rotate(angle); 161 162 return 1; 163 } 164 165 int UI_Lua::setText(lua_State *luaVM){ 166 int n = lua_gettop(luaVM); // Number of arguments 167 if (n != 2) 168 return luaL_error(luaVM, "Got %d arguments expected 2 (self, text)", n); 169 170 Label **label= (Label**)lua_touserdata(luaVM,1); 171 string text = luaL_checkstring(luaVM, 2); 172 (*label)->setText(text); 173 174 return 1; 175 }
Note: See TracChangeset
for help on using the changeset viewer.