├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── delivered └── lua │ └── include │ └── lua │ ├── lauxlib.h │ ├── lua.h │ ├── lua.hpp │ ├── luaconf.h │ └── lualib.h ├── demo ├── asteroid │ ├── assets │ │ ├── bullet.png │ │ ├── health.png │ │ ├── piercingBullet.png │ │ ├── powerup.png │ │ ├── rock.png │ │ ├── ship.png │ │ └── visitor1.ttf │ ├── class.lua │ ├── engine │ │ ├── body.lua │ │ ├── entity.lua │ │ ├── game.lua │ │ ├── gamepad.lua │ │ ├── health.lua │ │ ├── physic.lua │ │ ├── view.lua │ │ └── weapon.lua │ ├── game │ │ └── ship.lua │ ├── main.lua │ ├── sfmlobject │ │ ├── keypad.lua │ │ └── spriteview.lua │ └── signal.lua ├── demo.lua ├── minesweeper │ ├── class.lua │ ├── game.lua │ ├── main.lua │ ├── minesweeper.png │ └── sound │ │ ├── alarm.ogg │ │ ├── loose.ogg │ │ ├── minefound.ogg │ │ ├── nothing.ogg │ │ ├── start.ogg │ │ └── win.ogg ├── pong │ ├── pong.lua │ └── sansation.ttf └── tetris │ ├── class.lua │ ├── game.lua │ ├── main.lua │ ├── tetris_tiles-53.png │ └── timer.lua └── src ├── bindingHelper ├── enum.cpp ├── enum.hpp ├── lua_template.cpp ├── lua_template.hpp ├── macro2.hpp ├── marco.hpp ├── utils.cpp └── utils.hpp ├── external ├── graphics │ ├── BorderImage.cpp │ ├── BorderImage.h │ ├── SGItem.cpp │ ├── SGItem.h │ ├── tilemap.cpp │ └── tilemap.h └── graphics_wrap │ ├── wrap_sgitem.cpp │ ├── wrap_sgitem.h │ ├── wrap_tilemap.cpp │ └── wrap_tilemap.h ├── main.cpp └── sfml ├── audio.cpp ├── audio.h ├── audio ├── wrap_music.cpp ├── wrap_music.h ├── wrap_sound.cpp ├── wrap_sound.h ├── wrap_soundbuffer.cpp └── wrap_soundbuffer.h ├── graphics.cpp ├── graphics.h ├── graphics ├── wrap_circle_shape.cpp ├── wrap_circle_shape.h ├── wrap_color.cpp ├── wrap_color.h ├── wrap_drawable.cpp ├── wrap_drawable.h ├── wrap_float_rect.cpp ├── wrap_float_rect.h ├── wrap_font.cpp ├── wrap_font.h ├── wrap_int_rect.cpp ├── wrap_int_rect.h ├── wrap_rectangle_shape.cpp ├── wrap_rectangle_shape.h ├── wrap_render_window.cpp ├── wrap_render_window.h ├── wrap_sprite.cpp ├── wrap_sprite.h ├── wrap_text.cpp ├── wrap_text.h ├── wrap_texture.cpp └── wrap_texture.h ├── sfml.cpp ├── sfml.h ├── system.cpp ├── system.h ├── system ├── wrap_clock.cpp ├── wrap_clock.h ├── wrap_time.cpp ├── wrap_time.h ├── wrap_vector2f.cpp ├── wrap_vector2f.h ├── wrap_vector2i.cpp ├── wrap_vector2i.h ├── wrap_vector2u.cpp ├── wrap_vector2u.h ├── wrap_vector3f.cpp ├── wrap_vector3f.h ├── wrap_vector3i.cpp └── wrap_vector3i.h ├── window.cpp ├── window.h └── window ├── event ├── wrap_key_event.cpp ├── wrap_key_event.h ├── wrap_mouse_button_event.cpp ├── wrap_mouse_button_event.h ├── wrap_mouse_move_event.cpp ├── wrap_mouse_move_event.h ├── wrap_mouse_wheel_event.cpp ├── wrap_mouse_wheel_event.h ├── wrap_size_event.cpp └── wrap_size_event.h ├── wrap_event.cpp ├── wrap_event.h ├── wrap_keyboard.cpp ├── wrap_keyboard.h ├── wrap_mouse.cpp ├── wrap_mouse.h ├── wrap_videomode.cpp ├── wrap_videomode.h ├── wrap_window.cpp └── wrap_window.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | # xcode noise 16 | build/* 17 | *.pbxuser 18 | *.mode1v3 19 | 20 | # old skool 21 | .svn 22 | 23 | # osx noise 24 | .DS_Store 25 | profile 26 | 27 | *.user 28 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(luaSFML) 4 | set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") 5 | 6 | if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") 7 | add_definitions(-DLUA_USE_APICHECK) 8 | endif() 9 | 10 | file( GLOB_RECURSE SRC_LIST src/* game/*) 11 | 12 | if(${BUILD_TYPE} STREQUAL "Lib") 13 | add_library(${PROJECT_NAME} SHARED ${SRC_LIST}) 14 | add_definitions(-DBUILD_LIB) 15 | else() 16 | add_executable(${PROJECT_NAME} ${SRC_LIST}) 17 | 18 | endif() 19 | 20 | target_link_libraries(${PROJECT_NAME} lua) 21 | target_link_libraries(${PROJECT_NAME} sfml-system) 22 | target_link_libraries(${PROJECT_NAME} sfml-window) 23 | target_link_libraries(${PROJECT_NAME} sfml-graphics) 24 | target_link_libraries(${PROJECT_NAME} sfml-audio) 25 | 26 | #set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-save-temps") 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Canadadry 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | luaSFML 2 | ======= 3 | 4 | luaSFML is a lua binding of SFML, which let's you use SFML in your lua script. luaSFML attempts to be as compatible with SFML as possible, since lua is limited in terme of raw pointer and low level capabilities. 5 | 6 | 7 | Naming Convention 8 | ================= 9 | 10 | There is no documentation at the moment. So if you want to learn how to use luaSFML you will first need to learn C++ SFML version. 11 | 12 | To create a new instance of SFML object call the new function of the object. The class are bind to lua by concatenate sf namespace and class name. Ex: sf::Texture is bing under the name of sfTexture. 13 | Example to create a new sf::Texture call the new static function of sfTexture object like this : 14 | myTexture = stTexture.new() 15 | 16 | to learn more about luaSFML take a look at demos. 17 | 18 | 19 | Binding Completude 20 | ================== 21 | 22 | At the moment the binding is not complete. It's not a issue of feasability it's a issue of time. I've write this to write game quickly with SFML. 23 | But is enough advance to let you write your game. Only hight level feature are not bind like network, 3D sound spatialisation, renderTexture, shader ,vertex array and thread. 24 | The completude of this binding will evolve with my SFML need for my game dev. I'm sure the graphical binding will be the first to be completed. 25 | 26 | 27 | I've also added some object I need like tilemap. 28 | 29 | 30 | Building luaSFML 31 | ================ 32 | 33 | To build luaSFML you will need CMake 2.8 or higher, SFML 2.0 or higher, lua 5.1 and C++11 34 | You may need to edit CMakeList.txt in order to specify path to SFML and lua. 35 | 36 | Let me know if you have encounter a bug or if you need anything. 37 | 38 | -------------------------------------------------------------------------------- /delivered/lua/include/lua/lauxlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions for building Lua libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lauxlib_h 9 | #define lauxlib_h 10 | 11 | 12 | #include 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | 18 | #if defined(LUA_COMPAT_GETN) 19 | LUALIB_API int (luaL_getn) (lua_State *L, int t); 20 | LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); 21 | #else 22 | #define luaL_getn(L,i) ((int)lua_objlen(L, i)) 23 | #define luaL_setn(L,i,j) ((void)0) /* no op! */ 24 | #endif 25 | 26 | #if defined(LUA_COMPAT_OPENLIB) 27 | #define luaI_openlib luaL_openlib 28 | #endif 29 | 30 | 31 | /* extra error code for `luaL_load' */ 32 | #define LUA_ERRFILE (LUA_ERRERR+1) 33 | 34 | 35 | typedef struct luaL_Reg { 36 | const char *name; 37 | lua_CFunction func; 38 | } luaL_Reg; 39 | 40 | 41 | 42 | LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, 43 | const luaL_Reg *l, int nup); 44 | LUALIB_API void (luaL_register) (lua_State *L, const char *libname, 45 | const luaL_Reg *l); 46 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 47 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 48 | LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); 49 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); 50 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, 51 | size_t *l); 52 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, 53 | const char *def, size_t *l); 54 | LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); 55 | LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); 56 | 57 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); 58 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, 59 | lua_Integer def); 60 | 61 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 62 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); 63 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); 64 | 65 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 66 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 67 | 68 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); 69 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); 70 | 71 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, 72 | const char *const lst[]); 73 | 74 | LUALIB_API int (luaL_ref) (lua_State *L, int t); 75 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 76 | 77 | LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); 78 | LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, 79 | const char *name); 80 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 81 | 82 | LUALIB_API lua_State *(luaL_newstate) (void); 83 | 84 | 85 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, 86 | const char *r); 87 | 88 | LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, 89 | const char *fname, int szhint); 90 | 91 | 92 | 93 | 94 | /* 95 | ** =============================================================== 96 | ** some useful macros 97 | ** =============================================================== 98 | */ 99 | 100 | #define luaL_argcheck(L, cond,numarg,extramsg) \ 101 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) 102 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 103 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 104 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) 105 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) 106 | #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) 107 | #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) 108 | 109 | #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) 110 | 111 | #define luaL_dofile(L, fn) \ 112 | (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 113 | 114 | #define luaL_dostring(L, s) \ 115 | (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 116 | 117 | #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 118 | 119 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 120 | 121 | /* 122 | ** {====================================================== 123 | ** Generic Buffer manipulation 124 | ** ======================================================= 125 | */ 126 | 127 | 128 | 129 | typedef struct luaL_Buffer { 130 | char *p; /* current position in buffer */ 131 | int lvl; /* number of strings in the stack (level) */ 132 | lua_State *L; 133 | char buffer[LUAL_BUFFERSIZE]; 134 | } luaL_Buffer; 135 | 136 | #define luaL_addchar(B,c) \ 137 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ 138 | (*(B)->p++ = (char)(c))) 139 | 140 | /* compatibility only */ 141 | #define luaL_putchar(B,c) luaL_addchar(B,c) 142 | 143 | #define luaL_addsize(B,n) ((B)->p += (n)) 144 | 145 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); 146 | LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); 147 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); 148 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); 149 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); 150 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); 151 | 152 | 153 | /* }====================================================== */ 154 | 155 | 156 | /* compatibility with ref system */ 157 | 158 | /* pre-defined references */ 159 | #define LUA_NOREF (-2) 160 | #define LUA_REFNIL (-1) 161 | 162 | #define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ 163 | (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) 164 | 165 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) 166 | 167 | #define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) 168 | 169 | 170 | #define luaL_reg luaL_Reg 171 | 172 | #endif 173 | 174 | 175 | -------------------------------------------------------------------------------- /delivered/lua/include/lua/lua.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ 3 | ** Lua - An Extensible Extension Language 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 5 | ** See Copyright Notice at the end of this file 6 | */ 7 | 8 | 9 | #ifndef lua_h 10 | #define lua_h 11 | 12 | #include 13 | #include 14 | 15 | 16 | #include "luaconf.h" 17 | 18 | 19 | #define LUA_VERSION "Lua 5.1" 20 | #define LUA_RELEASE "Lua 5.1.4" 21 | #define LUA_VERSION_NUM 501 22 | #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" 23 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" 24 | 25 | 26 | /* mark for precompiled code (`Lua') */ 27 | #define LUA_SIGNATURE "\033Lua" 28 | 29 | /* option for multiple returns in `lua_pcall' and `lua_call' */ 30 | #define LUA_MULTRET (-1) 31 | 32 | 33 | /* 34 | ** pseudo-indices 35 | */ 36 | #define LUA_REGISTRYINDEX (-10000) 37 | #define LUA_ENVIRONINDEX (-10001) 38 | #define LUA_GLOBALSINDEX (-10002) 39 | #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) 40 | 41 | 42 | /* thread status; 0 is OK */ 43 | #define LUA_YIELD 1 44 | #define LUA_ERRRUN 2 45 | #define LUA_ERRSYNTAX 3 46 | #define LUA_ERRMEM 4 47 | #define LUA_ERRERR 5 48 | 49 | 50 | typedef struct lua_State lua_State; 51 | 52 | typedef int (*lua_CFunction) (lua_State *L); 53 | 54 | 55 | /* 56 | ** functions that read/write blocks when loading/dumping Lua chunks 57 | */ 58 | typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); 59 | 60 | typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); 61 | 62 | 63 | /* 64 | ** prototype for memory-allocation functions 65 | */ 66 | typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); 67 | 68 | 69 | /* 70 | ** basic types 71 | */ 72 | #define LUA_TNONE (-1) 73 | 74 | #define LUA_TNIL 0 75 | #define LUA_TBOOLEAN 1 76 | #define LUA_TLIGHTUSERDATA 2 77 | #define LUA_TNUMBER 3 78 | #define LUA_TSTRING 4 79 | #define LUA_TTABLE 5 80 | #define LUA_TFUNCTION 6 81 | #define LUA_TUSERDATA 7 82 | #define LUA_TTHREAD 8 83 | 84 | 85 | 86 | /* minimum Lua stack available to a C function */ 87 | #define LUA_MINSTACK 20 88 | 89 | 90 | /* 91 | ** generic extra include file 92 | */ 93 | #if defined(LUA_USER_H) 94 | #include LUA_USER_H 95 | #endif 96 | 97 | 98 | /* type of numbers in Lua */ 99 | typedef LUA_NUMBER lua_Number; 100 | 101 | 102 | /* type for integer functions */ 103 | typedef LUA_INTEGER lua_Integer; 104 | 105 | 106 | 107 | /* 108 | ** state manipulation 109 | */ 110 | LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); 111 | LUA_API void (lua_close) (lua_State *L); 112 | LUA_API lua_State *(lua_newthread) (lua_State *L); 113 | 114 | LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); 115 | 116 | 117 | /* 118 | ** basic stack manipulation 119 | */ 120 | LUA_API int (lua_gettop) (lua_State *L); 121 | LUA_API void (lua_settop) (lua_State *L, int idx); 122 | LUA_API void (lua_pushvalue) (lua_State *L, int idx); 123 | LUA_API void (lua_remove) (lua_State *L, int idx); 124 | LUA_API void (lua_insert) (lua_State *L, int idx); 125 | LUA_API void (lua_replace) (lua_State *L, int idx); 126 | LUA_API int (lua_checkstack) (lua_State *L, int sz); 127 | 128 | LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); 129 | 130 | 131 | /* 132 | ** access functions (stack -> C) 133 | */ 134 | 135 | LUA_API int (lua_isnumber) (lua_State *L, int idx); 136 | LUA_API int (lua_isstring) (lua_State *L, int idx); 137 | LUA_API int (lua_iscfunction) (lua_State *L, int idx); 138 | LUA_API int (lua_isuserdata) (lua_State *L, int idx); 139 | LUA_API int (lua_type) (lua_State *L, int idx); 140 | LUA_API const char *(lua_typename) (lua_State *L, int tp); 141 | 142 | LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); 143 | LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); 144 | LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); 145 | 146 | LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); 147 | LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); 148 | LUA_API int (lua_toboolean) (lua_State *L, int idx); 149 | LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); 150 | LUA_API size_t (lua_objlen) (lua_State *L, int idx); 151 | LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); 152 | LUA_API void *(lua_touserdata) (lua_State *L, int idx); 153 | LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); 154 | LUA_API const void *(lua_topointer) (lua_State *L, int idx); 155 | 156 | 157 | /* 158 | ** push functions (C -> stack) 159 | */ 160 | LUA_API void (lua_pushnil) (lua_State *L); 161 | LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); 162 | LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); 163 | LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); 164 | LUA_API void (lua_pushstring) (lua_State *L, const char *s); 165 | LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, 166 | va_list argp); 167 | LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); 168 | LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); 169 | LUA_API void (lua_pushboolean) (lua_State *L, int b); 170 | LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); 171 | LUA_API int (lua_pushthread) (lua_State *L); 172 | 173 | 174 | /* 175 | ** get functions (Lua -> stack) 176 | */ 177 | LUA_API void (lua_gettable) (lua_State *L, int idx); 178 | LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); 179 | LUA_API void (lua_rawget) (lua_State *L, int idx); 180 | LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); 181 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); 182 | LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); 183 | LUA_API int (lua_getmetatable) (lua_State *L, int objindex); 184 | LUA_API void (lua_getfenv) (lua_State *L, int idx); 185 | 186 | 187 | /* 188 | ** set functions (stack -> Lua) 189 | */ 190 | LUA_API void (lua_settable) (lua_State *L, int idx); 191 | LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); 192 | LUA_API void (lua_rawset) (lua_State *L, int idx); 193 | LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); 194 | LUA_API int (lua_setmetatable) (lua_State *L, int objindex); 195 | LUA_API int (lua_setfenv) (lua_State *L, int idx); 196 | 197 | 198 | /* 199 | ** `load' and `call' functions (load and run Lua code) 200 | */ 201 | LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); 202 | LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); 203 | LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); 204 | LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, 205 | const char *chunkname); 206 | 207 | LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); 208 | 209 | 210 | /* 211 | ** coroutine functions 212 | */ 213 | LUA_API int (lua_yield) (lua_State *L, int nresults); 214 | LUA_API int (lua_resume) (lua_State *L, int narg); 215 | LUA_API int (lua_status) (lua_State *L); 216 | 217 | /* 218 | ** garbage-collection function and options 219 | */ 220 | 221 | #define LUA_GCSTOP 0 222 | #define LUA_GCRESTART 1 223 | #define LUA_GCCOLLECT 2 224 | #define LUA_GCCOUNT 3 225 | #define LUA_GCCOUNTB 4 226 | #define LUA_GCSTEP 5 227 | #define LUA_GCSETPAUSE 6 228 | #define LUA_GCSETSTEPMUL 7 229 | 230 | LUA_API int (lua_gc) (lua_State *L, int what, int data); 231 | 232 | 233 | /* 234 | ** miscellaneous functions 235 | */ 236 | 237 | LUA_API int (lua_error) (lua_State *L); 238 | 239 | LUA_API int (lua_next) (lua_State *L, int idx); 240 | 241 | LUA_API void (lua_concat) (lua_State *L, int n); 242 | 243 | LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); 244 | LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); 245 | 246 | 247 | 248 | /* 249 | ** =============================================================== 250 | ** some useful macros 251 | ** =============================================================== 252 | */ 253 | 254 | #define lua_pop(L,n) lua_settop(L, -(n)-1) 255 | 256 | #define lua_newtable(L) lua_createtable(L, 0, 0) 257 | 258 | #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) 259 | 260 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) 261 | 262 | #define lua_strlen(L,i) lua_objlen(L, (i)) 263 | 264 | #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) 265 | #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) 266 | #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) 267 | #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) 268 | #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) 269 | #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) 270 | #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) 271 | #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) 272 | 273 | #define lua_pushliteral(L, s) \ 274 | lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) 275 | 276 | #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) 277 | #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) 278 | 279 | #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) 280 | 281 | 282 | 283 | /* 284 | ** compatibility macros and functions 285 | */ 286 | 287 | #define lua_open() luaL_newstate() 288 | 289 | #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) 290 | 291 | #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) 292 | 293 | #define lua_Chunkreader lua_Reader 294 | #define lua_Chunkwriter lua_Writer 295 | 296 | 297 | /* hack */ 298 | LUA_API void lua_setlevel (lua_State *from, lua_State *to); 299 | 300 | 301 | /* 302 | ** {====================================================================== 303 | ** Debug API 304 | ** ======================================================================= 305 | */ 306 | 307 | 308 | /* 309 | ** Event codes 310 | */ 311 | #define LUA_HOOKCALL 0 312 | #define LUA_HOOKRET 1 313 | #define LUA_HOOKLINE 2 314 | #define LUA_HOOKCOUNT 3 315 | #define LUA_HOOKTAILRET 4 316 | 317 | 318 | /* 319 | ** Event masks 320 | */ 321 | #define LUA_MASKCALL (1 << LUA_HOOKCALL) 322 | #define LUA_MASKRET (1 << LUA_HOOKRET) 323 | #define LUA_MASKLINE (1 << LUA_HOOKLINE) 324 | #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) 325 | 326 | typedef struct lua_Debug lua_Debug; /* activation record */ 327 | 328 | 329 | /* Functions to be called by the debuger in specific events */ 330 | typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); 331 | 332 | 333 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); 334 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); 335 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); 336 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); 337 | LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); 338 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); 339 | 340 | LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); 341 | LUA_API lua_Hook lua_gethook (lua_State *L); 342 | LUA_API int lua_gethookmask (lua_State *L); 343 | LUA_API int lua_gethookcount (lua_State *L); 344 | 345 | 346 | struct lua_Debug { 347 | int event; 348 | const char *name; /* (n) */ 349 | const char *namewhat; /* (n) `global', `local', `field', `method' */ 350 | const char *what; /* (S) `Lua', `C', `main', `tail' */ 351 | const char *source; /* (S) */ 352 | int currentline; /* (l) */ 353 | int nups; /* (u) number of upvalues */ 354 | int linedefined; /* (S) */ 355 | int lastlinedefined; /* (S) */ 356 | char short_src[LUA_IDSIZE]; /* (S) */ 357 | /* private part */ 358 | int i_ci; /* active function */ 359 | }; 360 | 361 | /* }====================================================================== */ 362 | 363 | 364 | /****************************************************************************** 365 | * Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. 366 | * 367 | * Permission is hereby granted, free of charge, to any person obtaining 368 | * a copy of this software and associated documentation files (the 369 | * "Software"), to deal in the Software without restriction, including 370 | * without limitation the rights to use, copy, modify, merge, publish, 371 | * distribute, sublicense, and/or sell copies of the Software, and to 372 | * permit persons to whom the Software is furnished to do so, subject to 373 | * the following conditions: 374 | * 375 | * The above copyright notice and this permission notice shall be 376 | * included in all copies or substantial portions of the Software. 377 | * 378 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 379 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 380 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 381 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 382 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 383 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 384 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 385 | ******************************************************************************/ 386 | 387 | 388 | #endif 389 | -------------------------------------------------------------------------------- /delivered/lua/include/lua/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /delivered/lua/include/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* Key to file-handle type */ 15 | #define LUA_FILEHANDLE "FILE*" 16 | 17 | 18 | #define LUA_COLIBNAME "coroutine" 19 | LUALIB_API int (luaopen_base) (lua_State *L); 20 | 21 | #define LUA_TABLIBNAME "table" 22 | LUALIB_API int (luaopen_table) (lua_State *L); 23 | 24 | #define LUA_IOLIBNAME "io" 25 | LUALIB_API int (luaopen_io) (lua_State *L); 26 | 27 | #define LUA_OSLIBNAME "os" 28 | LUALIB_API int (luaopen_os) (lua_State *L); 29 | 30 | #define LUA_STRLIBNAME "string" 31 | LUALIB_API int (luaopen_string) (lua_State *L); 32 | 33 | #define LUA_MATHLIBNAME "math" 34 | LUALIB_API int (luaopen_math) (lua_State *L); 35 | 36 | #define LUA_DBLIBNAME "debug" 37 | LUALIB_API int (luaopen_debug) (lua_State *L); 38 | 39 | #define LUA_LOADLIBNAME "package" 40 | LUALIB_API int (luaopen_package) (lua_State *L); 41 | 42 | 43 | /* open all previous libraries */ 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); 45 | 46 | 47 | 48 | #ifndef lua_assert 49 | #define lua_assert(x) ((void)0) 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /demo/asteroid/assets/bullet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/asteroid/assets/bullet.png -------------------------------------------------------------------------------- /demo/asteroid/assets/health.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/asteroid/assets/health.png -------------------------------------------------------------------------------- /demo/asteroid/assets/piercingBullet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/asteroid/assets/piercingBullet.png -------------------------------------------------------------------------------- /demo/asteroid/assets/powerup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/asteroid/assets/powerup.png -------------------------------------------------------------------------------- /demo/asteroid/assets/rock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/asteroid/assets/rock.png -------------------------------------------------------------------------------- /demo/asteroid/assets/ship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/asteroid/assets/ship.png -------------------------------------------------------------------------------- /demo/asteroid/assets/visitor1.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/asteroid/assets/visitor1.ttf -------------------------------------------------------------------------------- /demo/asteroid/class.lua: -------------------------------------------------------------------------------- 1 | function class(cls) 2 | -- local cls = {} 3 | cls.__index = cls 4 | cls.new = function (c, ...) 5 | local instance = setmetatable({}, cls) 6 | if instance.init then 7 | instance:init(...) 8 | end 9 | return instance 10 | end 11 | return cls 12 | end 13 | -------------------------------------------------------------------------------- /demo/asteroid/engine/body.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | 3 | Body = class({x=0,y=0,angle=0,radius=0}) 4 | 5 | function Body:init(entity) 6 | self.entity = entity 7 | end 8 | 9 | function Body:testCollision(entity) 10 | local dx = self.x - entity.body.x; 11 | local dy = self.y - entity.body.y; 12 | 13 | return ((dx * dx) + (dy * dy)) <= (self.radius + otherEntity.body.radius) 14 | end 15 | 16 | -------------------------------------------------------------------------------- /demo/asteroid/engine/entity.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | local signal = require "signal" 3 | 4 | Entity = class({}) 5 | 6 | function Entity:init() 7 | self.onCreated = signal.new() 8 | self.onDestroyed = signal.new() 9 | end 10 | 11 | function Entity:handleEvent(event) 12 | if(self.gamepad) then self.gamepad:handleEvent(event) end 13 | end 14 | 15 | 16 | function Entity:update() 17 | if(self.gamepad) then self.gamepad:update() end 18 | if(self.physic) then self.physic:update() end 19 | if(self.view) then self.view:update() end 20 | end 21 | 22 | function Entity:destroyed() 23 | self.onDestroyed.dispatch(self) 24 | end 25 | 26 | function Entity:render() 27 | if(self.view) then self.view:render() end 28 | end 29 | -------------------------------------------------------------------------------- /demo/asteroid/engine/game.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | local signal = require "signal" 3 | 4 | 5 | Game = class({isPaused=false, entities= {}}) 6 | 7 | function Game:loop() 8 | if not self.isPaused then 9 | self:forEachEntities("handleEvent") 10 | self:forEachEntities("update") 11 | end 12 | self:forEachEntities("render") 13 | end 14 | 15 | function Game:forEachEntities(func, ...) 16 | local entity = next(self.entities); 17 | while entity do 18 | entity[func](entity,...) 19 | entity = next(self.entities,entity) 20 | end 21 | end 22 | 23 | function Game:addEntity(entity) 24 | self.entities[entity] = entity; 25 | end 26 | 27 | -------------------------------------------------------------------------------- /demo/asteroid/engine/gamepad.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | 3 | GamePad = class({}) 4 | 5 | 6 | function GamePad:init(entity) 7 | self.entity = entity 8 | end 9 | 10 | function GamePad:update() 11 | end 12 | 13 | function GamePad:handleEvent(event) 14 | end 15 | -------------------------------------------------------------------------------- /demo/asteroid/engine/health.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | local signal = require "signal" 3 | 4 | Health = class({hits=0}) 5 | 6 | function Health:init(entity) 7 | self.entity = entity 8 | self.died = signal.new() 9 | self.hurt = signal.new() 10 | end 11 | 12 | function Health:hit(damage) 13 | self.hits = self.hits - damage; 14 | self.hurt.dispatch(self); 15 | if self.hits < 0 then 16 | self.died.dispatch(self); 17 | end 18 | end -------------------------------------------------------------------------------- /demo/asteroid/engine/physic.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | 3 | Physic = class({drag=1,velocityX=0,velocityY=0}) 4 | 5 | function Physic:init(entity) 6 | self.entity = entity 7 | end 8 | 9 | function Physic:update() 10 | self.entity.body.x = self.entity.body.x + self.velocityX; 11 | self.entity.body.y = self.entity.body.y + self.velocityY; 12 | 13 | self.velocityX = self.velocityX * self.drag; 14 | self.velocityY = self.velocityY * self.drag; 15 | end 16 | 17 | function Physic:thrust(power) 18 | self.velocityX = self.velocityX + math.sin(math.pi-math.rad(self.entity.body.angle)) * power 19 | self.velocityY = self.velocityY + math.cos(math.pi-math.rad(self.entity.body.angle)) * power 20 | end -------------------------------------------------------------------------------- /demo/asteroid/engine/view.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | 3 | View = class({}) 4 | 5 | function View:init(entity) 6 | self.entity = entity 7 | end 8 | 9 | function View:update() 10 | print("updating entity ".. tostring(self)); 11 | end 12 | 13 | 14 | 15 | function View:render() 16 | print("rendering entity ".. tostring(self)); 17 | end 18 | 19 | -------------------------------------------------------------------------------- /demo/asteroid/engine/weapon.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | 3 | Weapon = class({ammo=0}) 4 | 5 | function Weapon:init(entity) 6 | self.entity = entity 7 | end 8 | 9 | function Weapon:fire() 10 | self.ammo = self.ammo - 1; 11 | end -------------------------------------------------------------------------------- /demo/asteroid/game/ship.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | require "engine/entity" 3 | require "engine/body" 4 | require "engine/physic" 5 | require "sfmlobject/spriteview" 6 | require "sfmlobject/keypad" 7 | 8 | 9 | Ship = class(Entity:new()) 10 | 11 | function Ship:init(x,y) 12 | 13 | self.body = Body:new(self) 14 | self.body.x = 400 15 | self.body.y = 300 16 | self.body.angle = 180 17 | self.body.radius = 10 18 | 19 | self.physic = Physic:new(self) 20 | self.physic.drag = 0.9 21 | 22 | self.gamepad = KeyPad:new(self) 23 | self.gamepad.power = 2 24 | 25 | 26 | 27 | self.view = SpriteView:new(self,"ship.png") 28 | 29 | 30 | end -------------------------------------------------------------------------------- /demo/asteroid/main.lua: -------------------------------------------------------------------------------- 1 | require "SFML" 2 | require "engine/game" 3 | require "game/ship" 4 | 5 | print("use enum press ".. sfEventType.KeyPressed.. " release " .. sfEventType.KeyReleased .. " left " .. sfKey.Left .. " right ".. sfKey.Right .. " up "..sfKey.Up .. " down ".. sfKey.Down) 6 | 7 | math.randomseed(os.time()) 8 | 9 | window = sfRenderWindow.new(sfVideoMode.new(800,600,32),"Asteroid",sfWindowStyle.Default); 10 | window:setFramerateLimit(30) 11 | window:setKeyRepeatEnabled(false) 12 | 13 | game = Game.new(); 14 | ship = Ship:new(); 15 | game:addEntity(ship) 16 | 17 | clearColor = sfColor.new(0,0,0); 18 | 19 | event = sfEvent.new(); 20 | while window:isOpen() do 21 | i = 0; 22 | while window:pollEvent(event) do 23 | if(event:type() == sfEventType.Closed) then window:close(); 24 | elseif(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Escape ) then window:close(); 25 | elseif(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Q and event:key():system() == true ) then window:close(); 26 | else game:forEachEntities("handleEvent",event) 27 | end 28 | end 29 | window:clear(clearColor); 30 | 31 | game:forEachEntities("update") 32 | game:forEachEntities("render") 33 | window:display(); 34 | end 35 | 36 | -------------------------------------------------------------------------------- /demo/asteroid/sfmlobject/keypad.lua: -------------------------------------------------------------------------------- 1 | require "engine/gamepad" 2 | require "SFML" 3 | 4 | KeyPad = class(GamePad:new()) 5 | 6 | 7 | function KeyPad:init(entity,speed,power) 8 | self.entity = entity 9 | self.rotate = "none" 10 | self.move = "none" 11 | self.speed = speed or 10 12 | self.power = power or 10 13 | end 14 | 15 | 16 | function KeyPad:update() 17 | if self.rotate == "left" then self.entity.body.angle = self.entity.body.angle - self.speed 18 | elseif self.rotate == "right" then self.entity.body.angle = self.entity.body.angle + self.speed 19 | end 20 | 21 | if self.move == "forward" then self.entity.physic:thrust( self.power) 22 | elseif self.move == "backward" then self.entity.physic:thrust(-self.power) 23 | end 24 | 25 | print(" rotate " .. self.rotate .. " move ".. self.move) 26 | end 27 | 28 | function KeyPad:handleEvent(event) 29 | 30 | if (event:type() == sfEventType.KeyPressed and event:key():code() == sfKey.Left and self.rotate == "none") 31 | then self.rotate = "left" 32 | elseif(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Left and self.rotate == "left") 33 | then self.rotate = "none" 34 | elseif(event:type() == sfEventType.KeyPressed and event:key():code() == sfKey.Right and self.rotate == "none") 35 | then self.rotate = "right" 36 | elseif(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Right and self.rotate == "right") 37 | then self.rotate = "none" 38 | 39 | elseif(event:type() == sfEventType.KeyPressed and event:key():code() == sfKey.Up and self.move == "none") 40 | then self.move = "forward" 41 | elseif(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Up and self.move == "forward" ) 42 | then self.move = "none" 43 | elseif(event:type() == sfEventType.KeyPressed and event:key():code() == sfKey.Down and self.move == "none") 44 | then self.move = "backward" 45 | elseif(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Down and self.move == "backward") 46 | then self.move = "none" end 47 | 48 | end 49 | -------------------------------------------------------------------------------- /demo/asteroid/sfmlobject/spriteview.lua: -------------------------------------------------------------------------------- 1 | require "engine/view" 2 | require "SFML" 3 | 4 | SpriteView = class(View:new()) 5 | 6 | function SpriteView:init(entity,sprite) 7 | self.entity = entity 8 | self.texture = sfTexture.new() 9 | self.texture:loadFromFile("assets/"..sprite) 10 | self.sprite = sfSprite.new(self.texture) 11 | self.sprite:setOrigin(self.texture:getSize()/2) 12 | end 13 | 14 | function SpriteView:update() 15 | self.sprite:setPosition(self.entity.body.x,self.entity.body.y) 16 | self.sprite:setRotation(self.entity.body.angle) 17 | end 18 | 19 | function SpriteView:render() 20 | window:draw(self.sprite) 21 | end 22 | -------------------------------------------------------------------------------- /demo/asteroid/signal.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | signal.lua 3 | Copyright (c) 2011 Josh Tynjala 4 | Released under the MIT license. 5 | 6 | Based on as3-signals by Robert Penner 7 | http://github.com/robertpenner/as3-signals 8 | Copyright (c) 2009 Robert Penner 9 | Released under the MIT license. 10 | ]]-- 11 | module(..., package.seeall) 12 | 13 | local function indexOf(t, value, start) 14 | if start == nil then 15 | start = 1 16 | end 17 | for i,v in ipairs(t) do 18 | if i >= start and v == value then 19 | return i 20 | end 21 | end 22 | return nil 23 | end 24 | 25 | local listenerMT = {}; 26 | 27 | --this is used by the == comparison in indexOf 28 | listenerMT.__eq = function (a, b) 29 | return a.func == b.func and a.scope == b.scope 30 | end 31 | 32 | local function newListener(func, scope) 33 | local listener = 34 | { 35 | func = func, 36 | scope = scope 37 | } 38 | setmetatable(listener, listenerMT) 39 | 40 | return listener 41 | end 42 | 43 | function new() 44 | local signal = {} 45 | local listeners = {} 46 | local oneTimeListeners = {} 47 | 48 | signal.numListeners = 0 49 | 50 | function signal:add(func, scope) 51 | if func == nil then 52 | error("Function passed to signal:add() must not non-nil.") 53 | end 54 | local listener = newListener(func, scope) 55 | table.insert(listeners, listener) 56 | self.numListeners = self.numListeners + 1 57 | return listener 58 | end 59 | 60 | function signal:addOnce(func, scope) 61 | local listener = self:add(listener) 62 | table.insert(oneTimeListeners, listener) 63 | return listener 64 | end 65 | 66 | function signal:dispatch(...) 67 | for i,listener in ipairs(listeners) do 68 | if listener.scope then 69 | listener.func(listener.scope, unpack(arg)) 70 | else 71 | listener.func(unpack(arg)) 72 | end 73 | end 74 | 75 | for i,listener in ipairs(oneTimeListeners) do 76 | self:remove(listener) 77 | end 78 | end 79 | 80 | function signal:remove(func, scope) 81 | local listener 82 | if type(func) == "function" then 83 | listener = newListener(func, scope) 84 | else 85 | --special case used by removeAll so that we don't need to create 86 | --a new instance of the listener 87 | listener = func 88 | end 89 | local index = indexOf(listeners, listener) 90 | if index ~= nil then 91 | table.remove(listeners, index) 92 | self.numListeners = self.numListeners - 1 93 | 94 | --check if it was a one-time listener 95 | index = indexOf(oneTimeListeners, listener) 96 | if index ~= nil then 97 | table.remove(oneTimeListeners, index) 98 | end 99 | end 100 | 101 | end 102 | 103 | function signal:removeAll() 104 | while #listeners > 0 do 105 | self:remove(listeners[1]) 106 | end 107 | end 108 | 109 | return signal 110 | end -------------------------------------------------------------------------------- /demo/demo.lua: -------------------------------------------------------------------------------- 1 | 2 | 3 | math.randomseed(os.time()) 4 | 5 | window = sfRenderWindow.new(sfVideoMode.new(640,480,32),"Test",sfWindowStyle.Default); 6 | window:setFramerateLimit(30) 7 | 8 | 9 | circle = sfeSGItem.new(); 10 | circle:move(50,50); 11 | circle:setWidth(100); 12 | circle:setHeight(100); 13 | 14 | child1 = sfeSGItem.new(circle); 15 | child1:setWidth(50); 16 | child1:setHeight(50); 17 | 18 | 19 | clearColor = sfColor.new(math.random(256)-1,math.random(256)-1,math.random(256)-1); 20 | 21 | event = sfEvent.new(); 22 | while window:isOpen() do 23 | i = 0; 24 | while window:pollEvent(event) do 25 | if(event:type() == sfEventType.Closed) then window:close(); end 26 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Escape ) then window:close(); end 27 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Q and event:key():system() == true ) then window:close(); end 28 | end 29 | 30 | circle:rotate(1); 31 | child1:rotate(-2); 32 | 33 | window:clear(clearColor); 34 | window:draw(circle); 35 | window:display(); 36 | end 37 | 38 | -------------------------------------------------------------------------------- /demo/minesweeper/class.lua: -------------------------------------------------------------------------------- 1 | function class(cls) 2 | -- local cls = {} 3 | cls.__index = cls 4 | cls.new = function (c, ...) 5 | local instance = setmetatable({}, cls) 6 | if instance.init then 7 | instance:init(...) 8 | end 9 | return instance 10 | end 11 | return cls 12 | end 13 | -------------------------------------------------------------------------------- /demo/minesweeper/game.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | Game = class({ map, mapWidth, mapHeight, flagLeft, mineFound, mine, state ,tileChanged}) 3 | 4 | local TileDescription = { redFlag = 0, blueFlag = 1, mine = 2, redMine = 3, failMine = 4 , water = 5, empty = 6} 5 | local Tile = class({model_mineAround= 0, model_discovered= false, model_flaged=false}) 6 | 7 | local function shuffleTab(a) 8 | local j = 0; 9 | local valI = nil 10 | local valJ = nil 11 | local l = table.getn(a)-1; 12 | while (l > -1) do 13 | j = 1+math.floor(math.random() * l); 14 | valI = a[l]; 15 | valJ = a[j]; 16 | a[l] = valJ; 17 | a[j] = valI; 18 | l = l - 1; 19 | end 20 | return a; 21 | end 22 | 23 | 24 | function Game:restart() 25 | self:init(self.mapWidth, self.mapHeight ,self.mine) 26 | end 27 | 28 | function Game:init(w,h,m) 29 | self.mapWidth = w 30 | self.mapHeight = h 31 | self.flagLeft = m 32 | self.mineFound = 0 33 | self.mine = m 34 | self.state = "playing" 35 | self.tileChanged = nil 36 | 37 | self.map = {} 38 | for x=1,self.mapWidth do 39 | self.map[x] = {} 40 | for y=1,self.mapHeight do 41 | self.map[x][y] = Tile:new() 42 | end 43 | end 44 | 45 | local place = {} 46 | for i=0,self.mapWidth*self.mapHeight do 47 | place[i]=i 48 | end 49 | shuffleTab(place); 50 | for i=1,self.mine do 51 | local x= place[i]%self.mapWidth+1; 52 | local y= math.floor(place[i]/self.mapWidth)+1; 53 | self:placeMine(x,y) 54 | end 55 | 56 | self:allTileChanged() 57 | end 58 | 59 | function Game:inBound(x,y) 60 | return (x>=1 and y>=1 and x<=self.mapWidth and y<=self.mapHeight) 61 | end 62 | 63 | function Game:placeMine(x,y) 64 | if(self:inBound(x,y)) then 65 | 66 | if(self.map[x][y].model_mineAround == 9) then 67 | return false 68 | end 69 | self.map[x][y].model_mineAround=9; 70 | self:neighbourMinePlaced(x-1,y-1); 71 | self:neighbourMinePlaced(x ,y-1); 72 | self:neighbourMinePlaced(x+1,y-1); 73 | self:neighbourMinePlaced(x-1,y ); 74 | self:neighbourMinePlaced(x+1,y ); 75 | self:neighbourMinePlaced(x-1,y+1); 76 | self:neighbourMinePlaced(x ,y+1); 77 | self:neighbourMinePlaced(x+1,y+1); 78 | return true 79 | end 80 | return false 81 | end 82 | 83 | function Game:neighbourMinePlaced(x,y) 84 | if(self:inBound(x,y)) then 85 | if self.map[x][y].model_mineAround == 9 then 86 | return 87 | end 88 | 89 | self.map[x][y].model_mineAround = self.map[x][y].model_mineAround+1 90 | 91 | end 92 | 93 | end 94 | 95 | function Game:flag(x,y) 96 | local ret = false 97 | if(self:inBound(x,y)) then 98 | local gameBox = self.map[x][y] 99 | if( gameBox.model_discovered == false ) then 100 | if(self.flagLeft == 0 and gameBox.model_flaged == false) then 101 | return ret 102 | end 103 | ret = true 104 | if gameBox.model_flaged then 105 | self.flagLeft = self.flagLeft+1 106 | else 107 | self.flagLeft = self.flagLeft-1 108 | end 109 | 110 | gameBox.model_flaged = not gameBox.model_flaged; 111 | 112 | if(gameBox.model_mineAround == 9) then 113 | 114 | if gameBox.model_flaged then 115 | self.mineFound = self.mineFound+1 116 | else 117 | self.mineFound = self.mineFound-1 118 | end 119 | 120 | if(self.mineFound == self.mine) then 121 | self.state = "win" 122 | game:allTileChanged() 123 | end 124 | end 125 | 126 | if(self.tileChanged) then self.tileChanged(x,y,game:tileFromModel(self.map[x][y])); end 127 | end 128 | end 129 | end 130 | 131 | 132 | function Game:reveal(x,y) 133 | local ret = false 134 | if(self:inBound(x,y)) then 135 | 136 | local gameBox = self.map[x][y] 137 | if gameBox.model_discovered == false then 138 | if gameBox.model_flaged then return ret end 139 | gameBox.model_discovered = true 140 | ret = true 141 | 142 | if(gameBox.model_mineAround == 9) then 143 | gameBox.model_discovered = true 144 | self.state = "loose" 145 | game:allTileChanged() 146 | elseif(gameBox.model_mineAround == 0) then 147 | self:revealAround(x,y); 148 | end 149 | 150 | if(self.tileChanged) then self.tileChanged(x,y,game:tileFromModel(self.map[x][y])); end 151 | end 152 | end 153 | 154 | return ret; 155 | end 156 | 157 | function Game:revealAround(x,y) 158 | if(self:inBound(x,y)) then 159 | self:reveal(x-1,y-1); 160 | self:reveal(x ,y-1); 161 | self:reveal(x+1,y-1); 162 | self:reveal(x-1,y ); 163 | self:reveal(x+1,y ); 164 | self:reveal(x-1,y+1); 165 | self:reveal(x ,y+1); 166 | self:reveal(x+1,y+1); 167 | end 168 | end 169 | 170 | function Game:allTileChanged() 171 | if(self.tileChanged) then 172 | for x=1,self.mapWidth do 173 | for y=1,self.mapHeight do 174 | self.tileChanged(x,y,self:tileFromModel(self.map[x][y])); 175 | end 176 | end 177 | end 178 | if(self.stateChanged) then self.stateChanged(self.state); end 179 | end 180 | 181 | function Game:tileFromModel(model) 182 | local id = model.model_mineAround 183 | 184 | if self.state == "playing" then 185 | 186 | if model.model_discovered then 187 | return id+TileDescription.empty 188 | elseif model.model_flaged then 189 | return TileDescription.redFlag 190 | else 191 | return TileDescription.water 192 | end 193 | 194 | else 195 | if not model.model_flaged then 196 | if id == 0 then 197 | return TileDescription.empty 198 | elseif id == 9 then 199 | if model.model_discovered then 200 | return TileDescription.redMine 201 | else 202 | return TileDescription.mine 203 | end 204 | else 205 | return id+TileDescription.empty 206 | end 207 | elseif id == 9 then 208 | return TileDescription.redFlag 209 | else 210 | return TileDescription.failMine 211 | end 212 | end 213 | end 214 | -------------------------------------------------------------------------------- /demo/minesweeper/main.lua: -------------------------------------------------------------------------------- 1 | require "game" 2 | require "SFML" 3 | 4 | math.randomseed(os.time()) 5 | 6 | startBuffer = sfSoundBuffer.new(); 7 | startBuffer:loadFromFile("./sound/start.ogg") 8 | looseBuffer = sfSoundBuffer.new(); 9 | looseBuffer:loadFromFile("./sound/loose.ogg") 10 | nothingBuffer = sfSoundBuffer.new(); 11 | nothingBuffer:loadFromFile("./sound/nothing.ogg") 12 | winBuffer = sfSoundBuffer.new(); 13 | winBuffer:loadFromFile("./sound/win.ogg") 14 | sound = sfSound.new() 15 | 16 | function playBuffer(buf) 17 | sound:stop() 18 | sound:setBuffer(buf); 19 | sound:play() 20 | end 21 | 22 | playBuffer(startBuffer) 23 | 24 | gameParam = {w=15,h=15,m=30} 25 | tileSize = 20 26 | zoom= 1.5 27 | Game.tileChanged = function (x,y,id) 28 | tilemap:setIDForTile(id,x-1,y-1) 29 | end 30 | 31 | 32 | Game.stateChanged = function (newState) 33 | if newState == "win" then playBuffer(winBuffer) end 34 | if newState == "loose" then playBuffer(looseBuffer) end 35 | if newState == "playing" then playBuffer(startBuffer) end 36 | end 37 | 38 | 39 | window = sfRenderWindow.new(sfVideoMode.new(gameParam.w*tileSize*zoom,gameParam.h*tileSize*zoom,32),"Minesweeper",sfWindowStyle.Titlebar + sfWindowStyle.Close ); 40 | window:setFramerateLimit(30) 41 | 42 | texture = sfTexture.new(); 43 | texture:loadFromFile("minesweeper.png"); 44 | texture:setSmooth(true); 45 | 46 | tilemap = sfeTileMap.new(); 47 | tilemap:setSize(gameParam.w,gameParam.h); 48 | tilemap:setTexture(texture); 49 | tilemap:setTileSize(tileSize,tileSize); 50 | tilemap:scale(zoom,zoom) 51 | 52 | game = Game:new(gameParam.w,gameParam.h,gameParam.m); 53 | 54 | 55 | --window:setSize(game.mapWidth*tileSize,game.mapHeight*tileSize) 56 | --window:create(sfVideoMode.new(game.mapWidth*tileSize*zoom,game.mapHeight*tileSize*zoom,32),"Minesweeper",sfWindowStyle.Titlebar + sfWindowStyle.Close ) 57 | clearColor = sfColor.new(math.random(256)-1,math.random(256)-1,math.random(256)-1); 58 | 59 | event = sfEvent.new(); 60 | while window:isOpen() do 61 | i = 0; 62 | while window:pollEvent(event) do 63 | if(event:type() == sfEventType.Closed) then window:close(); end 64 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Escape ) then window:close(); end 65 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Q and event:key():system() == true ) then window:close(); end 66 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Space ) then game:restart(); end 67 | if(event:type() == sfEventType.MouseButtonPressed) then 68 | if game.state == "playing" then 69 | clickPos = sfMouse.getPositionRelativeto(window); 70 | if(event:mouseButton():button() == sfMouseButton.Left) then 71 | if game:reveal(math.floor(clickPos:x()/tileSize/zoom)+1,math.floor(clickPos:y()/tileSize/zoom)+1) then if game.state == "playing" then playBuffer(nothingBuffer) end end 72 | else 73 | game:flag(math.floor(clickPos:x()/tileSize/zoom)+1,math.floor(clickPos:y()/tileSize/zoom)+1) 74 | playBuffer(nothingBuffer) 75 | end 76 | end 77 | end 78 | end 79 | window:clear(clearColor); 80 | window:draw(tilemap); 81 | window:display(); 82 | end 83 | 84 | -------------------------------------------------------------------------------- /demo/minesweeper/minesweeper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/minesweeper/minesweeper.png -------------------------------------------------------------------------------- /demo/minesweeper/sound/alarm.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/minesweeper/sound/alarm.ogg -------------------------------------------------------------------------------- /demo/minesweeper/sound/loose.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/minesweeper/sound/loose.ogg -------------------------------------------------------------------------------- /demo/minesweeper/sound/minefound.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/minesweeper/sound/minefound.ogg -------------------------------------------------------------------------------- /demo/minesweeper/sound/nothing.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/minesweeper/sound/nothing.ogg -------------------------------------------------------------------------------- /demo/minesweeper/sound/start.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/minesweeper/sound/start.ogg -------------------------------------------------------------------------------- /demo/minesweeper/sound/win.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/minesweeper/sound/win.ogg -------------------------------------------------------------------------------- /demo/pong/pong.lua: -------------------------------------------------------------------------------- 1 | math.randomseed(os.time()) 2 | 3 | -- Define some constants 4 | pi = 3.14156535 5 | gameWidth = 800; 6 | gameHeight = 600; 7 | paddleSize = sfVector2f.new(25, 100); 8 | ballRadius = 10; 9 | colorWhite = sfColor.new(255, 255, 255) 10 | colorBlack = sfColor.new( 0, 0, 0) 11 | colorLeft = sfColor.new(100, 100, 200) 12 | colorRight = sfColor.new(200, 100, 100) 13 | 14 | -- Create the window of the application 15 | window = sfRenderWindow.new(sfVideoMode.new(gameWidth, gameHeight,32), "SFML Lua Pong",sfWindowStyle.Default); 16 | window:setVerticalSyncEnabled(true); 17 | 18 | 19 | -- Create the left paddle 20 | leftPaddle = sfRectangleShape.new(paddleSize - sfVector2f.new(3, 3)); 21 | leftPaddle:setOutlineThickness(3); 22 | leftPaddle:setOutlineColor(colorBlack); 23 | leftPaddle:setFillColor(colorLeft); 24 | leftPaddle:setOrigin(paddleSize / 2); 25 | 26 | -- Create the right paddle 27 | rightPaddle = sfRectangleShape.new(paddleSize - sfVector2f.new(3, 3)); 28 | rightPaddle:setOutlineThickness(3); 29 | rightPaddle:setOutlineColor(colorBlack); 30 | rightPaddle:setFillColor(colorRight); 31 | rightPaddle:setOrigin(paddleSize / 2); 32 | 33 | -- Create the ball 34 | ball = sfCircleShape.new(ballRadius - 3); 35 | ball:setOutlineThickness(3); 36 | ball:setOutlineColor(colorBlack); 37 | ball:setFillColor(colorWhite); 38 | ball:setOrigin(ballRadius/2,ballRadius/2); 39 | 40 | -- Load the text font 41 | font = sfFont.new() ; 42 | font:loadFromFile("sansation.ttf") 43 | 44 | -- Initialize the pause message 45 | pauseMessage = sfText.new("",font,40); 46 | pauseMessage:setPosition(170, 150); 47 | pauseMessage:setColor(colorWhite); 48 | pauseMessage:setString("Welcome to SFML pong!\nPress space to start the game"); 49 | 50 | -- Define the paddles properties 51 | AITimer = sfClock.new(); 52 | AITime = sfTime.seconds(0.1); 53 | paddleSpeed = 400; 54 | rightPaddleSpeed = 0; 55 | ballSpeed = 400; 56 | ballAngle = 0 57 | 58 | clock = sfClock.new() 59 | isPlaying = false; 60 | event = sfEvent.new() 61 | 62 | while window:isOpen() do 63 | -- Handle events 64 | while window:pollEvent(event) do 65 | if(event:type() == sfEventType.Closed) then window:close(); break; end 66 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Escape ) then window:close(); break; end 67 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Q and event:key():system() == true ) then window:close(); break; end 68 | 69 | 70 | -- Space key pressed: play 71 | if(event:type() == sfEventType.KeyPressed and event:key():code() == sfKey.Space ) then 72 | if not isPlaying then 73 | -- (re)start the game 74 | isPlaying = true; 75 | clock:restart(); 76 | 77 | -- Reset the position of the paddles and ball 78 | leftPaddle:setPosition(10 + paddleSize:x() / 2, gameHeight / 2); 79 | rightPaddle:setPosition(gameWidth - 10 - paddleSize:x() / 2, gameHeight / 2); 80 | ball:setPosition(gameWidth / 2, gameHeight / 2) 81 | 82 | -- Reset the ball angle 83 | repeat 84 | -- Make sure the ball initial angle is not too much vertical 85 | ballAngle = math.rad(math.random(360)); 86 | 87 | until (math.abs(math.cos(ballAngle)) > 0.7); 88 | end 89 | end 90 | end 91 | 92 | if isPlaying then 93 | deltaTime = clock:restart():asSeconds(); 94 | 95 | -- Move the player's paddle 96 | if sfKeyboard.isKeyPressed(sfKey.Up) and (leftPaddle:getPosition():y() - paddleSize:y() / 2 > 5) then 97 | leftPaddle:move(0, -paddleSpeed * deltaTime); 98 | end 99 | if sfKeyboard.isKeyPressed(sfKey.Down) and (leftPaddle:getPosition():y() + paddleSize:y() / 2 < gameHeight - 5) then 100 | leftPaddle:move(0, paddleSpeed * deltaTime) 101 | end 102 | 103 | -- Move the computer's paddle 104 | if (((rightPaddleSpeed < 0 ) and (rightPaddle:getPosition():y() - paddleSize:y() / 2 > 5)) or 105 | ((rightPaddleSpeed > 0) and (rightPaddle:getPosition():y() + paddleSize:y() / 2 < gameHeight - 5))) then 106 | 107 | rightPaddle:move(0, rightPaddleSpeed * deltaTime) 108 | end 109 | 110 | -- Update the computer's paddle direction according to the ball position 111 | if (AITimer:getElapsedTime() > AITime) then 112 | AITimer:restart() 113 | if (ball:getPosition():y() + ballRadius > rightPaddle:getPosition():y() + paddleSize:y() / 2) then 114 | rightPaddleSpeed = paddleSpeed; 115 | elseif (ball:getPosition():y() - ballRadius < rightPaddle:getPosition():y() - paddleSize:y() / 2) then 116 | rightPaddleSpeed = -paddleSpeed; 117 | else 118 | rightPaddleSpeed = 0 ; 119 | end 120 | end 121 | 122 | -- Move the ball 123 | factor = ballSpeed * deltaTime; 124 | ball:move(math.cos(ballAngle) * factor , math.sin(ballAngle) * factor) 125 | 126 | -- Check collisions between the ball and the screen 127 | if (ball:getPosition():x() - ballRadius < 0) then 128 | 129 | isPlaying = false; 130 | pauseMessage:setString("You lost !\nPress space to restart or\nescape to exit"); 131 | end 132 | if (ball:getPosition():x() + ballRadius > gameWidth) then 133 | isPlaying = false 134 | pauseMessage:setString("You won !\nPress space to restart or\nescape to exit"); 135 | end 136 | if (ball:getPosition():y() - ballRadius < 0) then 137 | ballAngle = -ballAngle; 138 | ball:setPosition(ball:getPosition():x(), ballRadius + 0.1) 139 | end 140 | if (ball:getPosition():y() + ballRadius > gameHeight) then 141 | ballAngle = -ballAngle; 142 | ball:setPosition(ball:getPosition():x(), gameHeight - ballRadius - 0.1) 143 | end 144 | 145 | -- Check the collisions between the ball and the paddles 146 | -- Left Paddle 147 | if (ball:getPosition():x() - ballRadius < leftPaddle:getPosition():x() + paddleSize:x() / 2 and 148 | ball:getPosition():x() - ballRadius > leftPaddle:getPosition():x() and 149 | ball:getPosition():y() + ballRadius >= leftPaddle:getPosition():y() - paddleSize:y() / 2 and 150 | ball:getPosition():y() - ballRadius <= leftPaddle:getPosition():y() + paddleSize:y() / 2) then 151 | if (ball:getPosition():y() > leftPaddle:getPosition():y()) then 152 | ballAngle = pi - ballAngle + math.rad(math.random(20)); 153 | else 154 | ballAngle = pi - ballAngle - math.rad(math.random(20)); 155 | end 156 | ball:setPosition(leftPaddle:getPosition():x() + ballRadius + paddleSize:x() / 2 + 0.1, ball:getPosition():y()) 157 | end 158 | 159 | -- Right Paddle 160 | if (ball:getPosition():x() + ballRadius > rightPaddle:getPosition():x() - paddleSize:x() / 2 and 161 | ball:getPosition():x() + ballRadius < rightPaddle:getPosition():x() and 162 | ball:getPosition():y() + ballRadius >= rightPaddle:getPosition():y() - paddleSize:y() / 2 and 163 | ball:getPosition():y() - ballRadius <= rightPaddle:getPosition():y() + paddleSize:y() / 2) then 164 | 165 | if (ball:getPosition():y() > rightPaddle:getPosition():y()) then 166 | ballAngle = pi - ballAngle --+ (std::rand() % 20) * pi / 180; 167 | else 168 | ballAngle = pi - ballAngle --- (std::rand() % 20) * pi / 180; 169 | end 170 | ball:setPosition(rightPaddle:getPosition():x() - ballRadius - paddleSize:x() / 2 - 0.1, ball:getPosition():y()) 171 | end 172 | end 173 | 174 | -- Clear the window 175 | window:clear(colorBlack); 176 | 177 | if (isPlaying) then 178 | -- Draw the paddles and the ball 179 | window:draw(leftPaddle); 180 | window:draw(rightPaddle); 181 | window:draw(ball); 182 | else 183 | -- Draw the pause message 184 | window:draw(pauseMessage); 185 | end 186 | -- Display things on screen 187 | window:display() 188 | end 189 | 190 | -------------------------------------------------------------------------------- /demo/pong/sansation.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/pong/sansation.ttf -------------------------------------------------------------------------------- /demo/tetris/class.lua: -------------------------------------------------------------------------------- 1 | function class(cls) 2 | -- local cls = {} 3 | cls.__index = cls 4 | cls.new = function (c, ...) 5 | local instance = setmetatable({}, cls) 6 | if instance.init then 7 | instance:init(...) 8 | end 9 | return instance 10 | end 11 | return cls 12 | end 13 | -------------------------------------------------------------------------------- /demo/tetris/game.lua: -------------------------------------------------------------------------------- 1 | require "class" 2 | 3 | Game = class{map = {}, state="stop" , w =10, h =16, currentTetrimino = nil}; 4 | 5 | 6 | function deepcopy(orig) 7 | local orig_type = type(orig) 8 | local copy 9 | if orig_type == 'table' then 10 | copy = {} 11 | for orig_key, orig_value in next, orig, nil do 12 | copy[deepcopy(orig_key)] = deepcopy(orig_value) 13 | end 14 | setmetatable(copy, deepcopy(getmetatable(orig))) 15 | else -- number, string, boolean, etc 16 | copy = orig 17 | end 18 | return copy 19 | end 20 | 21 | function transpose(tab) 22 | local copy = {} 23 | h = table.getn(tab[1]) 24 | w = table.getn(tab) 25 | 26 | for x=1,h do 27 | copy[x] = {} 28 | for y=1,w do 29 | copy[x][y] = tab[y][h-x+1] 30 | end 31 | end 32 | return copy 33 | end 34 | 35 | function tprint (tbl, indent) 36 | if not indent then indent = 0 end 37 | for k, v in pairs(tbl) do 38 | formatting = string.rep(" ", indent) .. k .. ": " 39 | if type(v) == "table" then 40 | print(formatting) 41 | tprint(v, indent+1) 42 | else 43 | print(formatting .. v) 44 | end 45 | end 46 | end 47 | 48 | local tetriminoList = { -- I 49 | {{1}, 50 | {1}, 51 | {1}, 52 | {1}}, 53 | -- J 54 | {{0,1}, 55 | {0,1}, 56 | {1,1}}, 57 | -- L 58 | {{1,0}, 59 | {1,0}, 60 | {1,1}}, 61 | -- O 62 | {{1,1}, 63 | {1,1}}, 64 | -- S 65 | {{0,1,1}, 66 | {1,1,0}}, 67 | -- Z 68 | {{1,1,0}, 69 | {0,1,1}}, 70 | -- T 71 | {{0,1,0}, 72 | {1,1,1}}, 73 | } 74 | 75 | local tetriminoCount = 7 76 | 77 | 78 | local Tetrimino = class{map = nil ,w=2,h=2, id = 1, col = 0, row = 0} 79 | 80 | function Tetrimino:init() 81 | self.id = math.random(tetriminoCount) 82 | self.map = deepcopy(tetriminoList[self.id]) 83 | self.h = table.getn(self.map[1]) 84 | self.w = table.getn(self.map) 85 | 86 | end 87 | 88 | function Game:init() 89 | for x=1,self.w do 90 | self.map[x] = {} 91 | for y=1,self.h do 92 | self.map[x][y] = 0 93 | self:onTileChanged(x,y,0); 94 | end 95 | end 96 | self:newTetrimino() 97 | self.state="play" 98 | 99 | 100 | end 101 | 102 | function Game:newTetrimino() 103 | self.currentTetrimino = Tetrimino:new() 104 | self.currentTetrimino.col=4 105 | self:drawTetrimino() 106 | end 107 | 108 | function Game:clearDrawTetrimino() 109 | local tetrimino=self.currentTetrimino 110 | for x=1,tetrimino.w do 111 | for y=1,tetrimino.h do 112 | if tetrimino.map[x][y] == 1 then self:onTileChanged(x+tetrimino.col,y+tetrimino.row,0) end 113 | end 114 | end 115 | end 116 | 117 | function Game:drawTetrimino() 118 | local tetrimino=self.currentTetrimino 119 | for x=1,tetrimino.w do 120 | for y=1,tetrimino.h do 121 | if tetrimino.map[x][y] == 1 then self:onTileChanged(x+tetrimino.col,y+tetrimino.row,tetrimino.id) end 122 | end 123 | end 124 | end 125 | 126 | function Game:step() 127 | if self.state ~= "play" then return end 128 | self.currentTetrimino.row = self.currentTetrimino.row+1; 129 | if self:checkCollision() == "free" then 130 | self.currentTetrimino.row = self.currentTetrimino.row-1; 131 | self:clearDrawTetrimino() 132 | self.currentTetrimino.row = self.currentTetrimino.row+1; 133 | self:drawTetrimino() 134 | else 135 | self.currentTetrimino.row = self.currentTetrimino.row-1; 136 | game:placeTetrimino() 137 | if self:checkCollision() ~= "free" then 138 | self.state = "stop"; 139 | else 140 | self:checkLine() 141 | end 142 | 143 | end 144 | end 145 | 146 | function Game:checkLine() 147 | 148 | local completedOnce = false 149 | for y=1,self.h do 150 | local completed = true 151 | for x=1,self.w do 152 | if self.map[x][y] == 0 then completed=false end 153 | end 154 | if completed then 155 | self:removeLine(y) 156 | completedOnce = true 157 | end 158 | end 159 | 160 | if completedOnce then self:allTileChanged() end 161 | end 162 | 163 | function Game:removeLine(line) 164 | for x=1,self.w do 165 | table.remove(self.map[x],line) 166 | table.insert(self.map[x],1,0) 167 | end 168 | end 169 | 170 | function Game:placeTetrimino() 171 | local tetrimino=self.currentTetrimino 172 | for x=1,tetrimino.w do 173 | for y=1,tetrimino.h do 174 | if tetrimino.map[x][y] == 1 then self.map[x+tetrimino.col][y+tetrimino.row] = tetrimino.id end 175 | end 176 | end 177 | self:newTetrimino() 178 | end 179 | 180 | function Game:checkCollision() 181 | local tetrimino=self.currentTetrimino 182 | for x=1,tetrimino.w do 183 | for y=1,tetrimino.h do 184 | if self:validPos(x+tetrimino.col,y+tetrimino.row) then 185 | if tetrimino.map[x][y] == 1 and self.map[x+tetrimino.col][y+tetrimino.row] > 0 then return "collide" end 186 | else 187 | return "out" 188 | end 189 | end 190 | end 191 | return "free" 192 | end 193 | 194 | function Game:rotateLeft() 195 | self:rotateRight() 196 | end 197 | 198 | function Game:rotateRight() 199 | if self.state ~= "play" then return end 200 | 201 | self:clearDrawTetrimino() 202 | 203 | local tetrimino=self.currentTetrimino 204 | tetrimino.map = transpose(tetrimino.map) 205 | tetrimino.w = table.getn(tetrimino.map) 206 | tetrimino.h = table.getn(tetrimino.map[1]) 207 | 208 | local inc = -1 209 | if(tetrimino.col < self.w/2) then inc = 1 end 210 | 211 | while self:checkCollision() == "out" do 212 | tetrimino.col = tetrimino.col+inc; 213 | end 214 | 215 | while self:checkCollision() == "collide" do 216 | tetrimino.col = tetrimino.row-1; 217 | end 218 | 219 | self:drawTetrimino() 220 | 221 | end 222 | 223 | function Game:moveLeft() 224 | if self.state ~= "play" then return end 225 | 226 | self.currentTetrimino.col = self.currentTetrimino.col-1; 227 | if self:checkCollision() == "free" then 228 | self.currentTetrimino.col = self.currentTetrimino.col+1; 229 | self:clearDrawTetrimino() 230 | self.currentTetrimino.col = self.currentTetrimino.col-1; 231 | self:drawTetrimino() 232 | else 233 | self.currentTetrimino.col = self.currentTetrimino.col+1; 234 | end 235 | end 236 | 237 | function Game:moveRight() 238 | if self.state ~= "play" then return end 239 | 240 | self.currentTetrimino.col = self.currentTetrimino.col+1; 241 | if self:checkCollision() == "free" then 242 | self.currentTetrimino.col = self.currentTetrimino.col-1; 243 | self:clearDrawTetrimino() 244 | self.currentTetrimino.col = self.currentTetrimino.col+1; 245 | self:drawTetrimino() 246 | else 247 | self.currentTetrimino.col = self.currentTetrimino.col-1; 248 | end 249 | end 250 | 251 | function Game:validPos(x,y) 252 | if self.map[x] == nil then return false end 253 | if self.map[x][y] == nil then return false end 254 | return true 255 | end 256 | 257 | function Game:allTileChanged() 258 | if(self.tileChanged) then 259 | for x=1,self.w do 260 | for y=1,self.h do 261 | self.tileChanged(x,y,self.map[x][y]); 262 | end 263 | end 264 | end 265 | end 266 | 267 | function Game:onTileChanged(x,y,id) 268 | if(self.tileChanged) then 269 | self.tileChanged(x,y,id); 270 | end 271 | end -------------------------------------------------------------------------------- /demo/tetris/main.lua: -------------------------------------------------------------------------------- 1 | require "game" 2 | --require "SFML" 3 | require "timer" 4 | 5 | math.randomseed(os.time()) 6 | 7 | 8 | tileSize = 53 9 | zoom= 1 10 | 11 | Game.tileChanged = function (x,y,id) 12 | tilemap:setIDForTile(id,x-1,y-1) 13 | end 14 | 15 | Game.stateChanged = function (newState) 16 | print("state "..newState) 17 | end 18 | 19 | window = sfRenderWindow.new(sfVideoMode.new(10*tileSize*zoom,16*tileSize*zoom,32),"Tetris",sfWindowStyle.Titlebar + sfWindowStyle.Close ); 20 | window:setFramerateLimit(30) 21 | window:setKeyRepeatEnabled(false) 22 | 23 | texture = sfTexture.new(); 24 | texture:loadFromFile("tetris_tiles-53.png"); 25 | texture:setSmooth(true); 26 | 27 | tilemap = sfeTileMap.new(); 28 | tilemap:setSize(10,16)--game.mapWidth,game.mapHeight); 29 | tilemap:setTexture(texture); 30 | tilemap:setTileSize(tileSize,tileSize); 31 | tilemap:scale(zoom,zoom) 32 | 33 | game = Game:new(); 34 | clearColor = sfColor.new(0,0,0); 35 | stepTimer = Timer:new(Game.step,game); 36 | stepTimer:start(1,true); 37 | 38 | event = sfEvent.new(); 39 | while window:isOpen() do 40 | i = 0; 41 | while window:pollEvent(event) do 42 | if(event:type() == sfEventType.Closed) then window:close(); end 43 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Escape ) then window:close(); end 44 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Q and event:key():system() == true ) then window:close(); end 45 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Left ) then game:moveLeft(); end 46 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Right) then game:moveRight(); end 47 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Space) then game:rotateRight(); end 48 | if(event:type() == sfEventType.KeyReleased and event:key():code() == sfKey.Down) then game:step(); end 49 | end 50 | stepTimer:update(); 51 | window:clear(clearColor); 52 | window:draw(tilemap); 53 | window:display(); 54 | end 55 | 56 | -------------------------------------------------------------------------------- /demo/tetris/tetris_tiles-53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/demo/tetris/tetris_tiles-53.png -------------------------------------------------------------------------------- /demo/tetris/timer.lua: -------------------------------------------------------------------------------- 1 | --require "SFML" 2 | require "class" 3 | 4 | Timer = class{clock = nil, loop = false, duration = 1.0,object =nil, trigerFunction = nil,playing = false} 5 | 6 | function Timer:init(func,object) 7 | self.trigerFunction = func 8 | self.object= object 9 | self.clock = sfClock.new() 10 | end 11 | 12 | 13 | function Timer:update() 14 | if not self.playing then return end 15 | if self.clock:getElapsedTime():asSeconds() > self.duration then 16 | self.clock:restart() 17 | self.trigerFunction(self.object) 18 | self.playing = self.loop 19 | end 20 | end 21 | 22 | function Timer:start(duration, loop) 23 | self.duration = duration or self.duration 24 | self.loop = loop or self.repeate 25 | self.playing = true 26 | self.clock:restart() 27 | end 28 | 29 | function Timer:stop() 30 | self.playing = false; 31 | end 32 | -------------------------------------------------------------------------------- /src/bindingHelper/enum.cpp: -------------------------------------------------------------------------------- 1 | #include "enum.hpp" 2 | #include 3 | #include 4 | #include 5 | 6 | bool add_enum_to_lua(lua_State* L, const char* tname, ...) 7 | { 8 | // NOTE: Here's the Lua code we're building and executing to define the 9 | // enum. 10 | // 11 | // = setmetatable( {}, { 12 | // __index = { 13 | // = { 14 | // value = , 15 | // type = \"\" 16 | // }, 17 | // ... 18 | // }, 19 | // __newindex = function(table, key, value) 20 | // error(\"Attempt to modify read-only table\") 21 | // end, 22 | // __metatable = false 23 | // }); 24 | 25 | va_list args; 26 | std::stringstream code; 27 | char* ename; 28 | int evalue; 29 | 30 | code << tname << " = setmetatable({}, {"; 31 | code << "__index = {"; 32 | 33 | // Iterate over the variadic arguments adding the enum values. 34 | va_start(args, tname); 35 | while ((ename = va_arg(args, char*)) != 0) 36 | { 37 | evalue = va_arg(args, int); 38 | code << ename << "=" << evalue << ", "; 39 | } 40 | va_end(args); 41 | 42 | code << "},"; 43 | code << "__newindex = function(table, key, value) error(\"Attempt to modify read-only table\") end,"; 44 | code << "__metatable = false});"; 45 | 46 | // Execute lua code 47 | if ( luaL_loadbuffer(L, code.str().c_str(), code.str().length(),0) || lua_pcall(L, 0, 0, 0) ) 48 | { 49 | fprintf(stderr, "%s\n", lua_tostring(L, -1)); 50 | lua_pop(L, 1); 51 | return false; 52 | } 53 | return true; 54 | } 55 | -------------------------------------------------------------------------------- /src/bindingHelper/enum.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _LUA_TYPED_ENUMS_H_ 3 | #define _LUA_TYPED_ENUMS_H_ 4 | 5 | #include 6 | 7 | // Adds an enumerated type into Lua. 8 | // 9 | // L - Lua state. 10 | // tname - The name of the enum type. 11 | // pairs, terminated by a null (0). 12 | // 13 | // EX: Assume the following enum in C-code: 14 | // 15 | // typedef enum _TYPE { TYPE_FOO=0, TYPE_BAR, TYPE_BAZ, TYPE_MAX } TYPE; 16 | // 17 | // To map this to Lua, do the following: 18 | // 19 | // add_enum_to_lua( L, "type", 20 | // "foo", TYPE_FOO, 21 | // "bar", TYPE_BAR, 22 | // "baz", TYPE_BAZ, 23 | // 0); 24 | // 25 | // In Lua, you can access the enum as: 26 | // type.foo 27 | // type.bar 28 | // type.baz 29 | // 30 | // You can print the value in Lua by: 31 | // > print(type.foo) 32 | // 33 | 34 | bool add_enum_to_lua(lua_State* L, const char* tname, ...); 35 | 36 | #endif // _LUA_TYPED_ENUMS_H_ 37 | -------------------------------------------------------------------------------- /src/bindingHelper/lua_template.cpp: -------------------------------------------------------------------------------- 1 | #include "lua_template.hpp" 2 | #include 3 | 4 | template<> 5 | int lua_get(lua_State * l,int i) 6 | { 7 | return luaL_checkinteger(l,i); 8 | } 9 | 10 | template<> 11 | unsigned int lua_get(lua_State * l,int i) 12 | { 13 | int value = (int)luaL_checkinteger(l,i); 14 | if(value < 0 ) luaL_argerror(l,i,"Must be strictly positive"); 15 | return value; 16 | } 17 | 18 | template<> 19 | unsigned char lua_get(lua_State * l,int i) 20 | { 21 | unsigned int value = lua_get(l,i); 22 | if(value > 255 ) luaL_argerror(l,i,"Must be inferior to 256"); 23 | return value; 24 | } 25 | 26 | 27 | template<> 28 | float lua_get(lua_State * l,int i) 29 | { 30 | return luaL_checknumber(l,i); 31 | } 32 | 33 | template<> 34 | double lua_get(lua_State * l,int i) 35 | { 36 | return luaL_checknumber(l,i); 37 | } 38 | 39 | template<> 40 | std::string lua_get(lua_State * l,int i) 41 | { 42 | size_t lenght = 0; 43 | const char* tmp = luaL_checklstring(l,i,&lenght); 44 | return std::string(tmp,lenght); 45 | } 46 | 47 | template<> 48 | bool lua_get(lua_State * l,int i) 49 | { 50 | return lua_toboolean(l,i) == 0; 51 | } 52 | 53 | template<> 54 | int lua_push(lua_State * l,const int& value) 55 | { 56 | lua_pushinteger(l,value); 57 | return 1; 58 | } 59 | 60 | template<> 61 | int lua_push(lua_State * l,const unsigned int& value) 62 | { 63 | lua_pushinteger(l,value); 64 | return 1; 65 | } 66 | 67 | template<> 68 | int lua_push(lua_State * l,const unsigned char& value) 69 | { 70 | lua_pushinteger(l,value); 71 | return 1; 72 | } 73 | 74 | template<> 75 | int lua_push(lua_State * l,const float& value) 76 | { 77 | lua_pushnumber(l,value); 78 | return 1; 79 | } 80 | 81 | template<> 82 | int lua_push(lua_State * l,const std::string& value) 83 | { 84 | lua_pushstring(l,value.c_str()); 85 | return 1; 86 | } 87 | 88 | template<> 89 | int lua_push(lua_State * l,const bool& value) 90 | { 91 | lua_pushboolean(l,value?1:0); 92 | return 1; 93 | } 94 | -------------------------------------------------------------------------------- /src/bindingHelper/lua_template.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __SFLUA__TEMPLATE__ 2 | #define __SFLUA__TEMPLATE__ 3 | 4 | #include 5 | #include 6 | #include "utils.hpp" 7 | 8 | template< typename T> 9 | T lua_get(lua_State * l,int i) 10 | { 11 | return check_pointertype(l,i); 12 | } 13 | 14 | template< typename T> 15 | int lua_push(lua_State * l,const T& value) 16 | { 17 | copy_constructor(l,value); 18 | return 1; 19 | } 20 | 21 | template<> 22 | int lua_get(lua_State * l,int i); 23 | 24 | template<> 25 | unsigned int lua_get(lua_State * l,int i); 26 | 27 | template<> 28 | unsigned char lua_get(lua_State * l,int i); 29 | 30 | template<> 31 | float lua_get(lua_State * l,int i); 32 | 33 | template<> 34 | double lua_get(lua_State * l,int i); 35 | 36 | template<> 37 | std::string lua_get(lua_State * l,int i); 38 | 39 | template<> 40 | bool lua_get(lua_State * l,int i); 41 | 42 | template<> 43 | int lua_push(lua_State * l,const int& value); 44 | 45 | template<> 46 | int lua_push(lua_State * l,const unsigned int& value); 47 | 48 | template<> 49 | int lua_push(lua_State * l,const unsigned char& value); 50 | 51 | template<> 52 | int lua_push(lua_State * l,const float& value); 53 | 54 | template<> 55 | int lua_push(lua_State * l,const std::string& value); 56 | 57 | template<> 58 | int lua_push(lua_State * l,const bool& value); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/bindingHelper/macro2.hpp: -------------------------------------------------------------------------------- 1 | #undef X0 2 | #undef X1 3 | #undef X2 4 | #undef X3 5 | 6 | #ifndef NAME_TO_BIND 7 | #error you must define the macro NAME_TO_BIND which should containt the name exposed to lua 8 | #endif 9 | 10 | #ifndef TYPE_TO_BIND 11 | #error you must define the macro TYPE_TO_BIND which should containt the type exposed to lua 12 | #endif 13 | 14 | 15 | #define BUILD_NAME(type,name) type##_##name 16 | 17 | #define HAS_RETURN(value1,value2) return value1(l, value2); 18 | #define NO_RETURN(value1,value2) value2;return 0; 19 | 20 | #define RET_CTOR RET_TYPE(TYPE_TO_BIND) 21 | #define RET_TYPE(type) lua_push 22 | #define RET_NONE 23 | 24 | #define NO_POINTER 25 | #define IS_POINTER * 26 | 27 | #define GET_PARAM(type, index,isPointer) isPointer lua_get(l,index) 28 | 29 | #define FUNCTION_0(functionToBind) functionToBind() 30 | #define METHOD_0(functionToBind) GET_PARAM(TYPE_TO_BIND*,1,NO_POINTER)->functionToBind() 31 | #define GETTER_0(functionToBind) GET_PARAM(TYPE_TO_BIND*,1,NO_POINTER)->functionToBind 32 | 33 | #define CALL_FUNCTION_0(type,functionToBind) type##_0(functionToBind) 34 | 35 | #define FUNCTION_1(functionToBind,firstParam,firstIsPointer) functionToBind( GET_PARAM(firstParam,1,firstIsPointer)) 36 | #define METHOD_1(functionToBind,firstParam,firstIsPointer) GET_PARAM(TYPE_TO_BIND*,1,NO_POINTER)->functionToBind( GET_PARAM(firstParam,2,firstIsPointer)) 37 | #define SETTER_1(functionToBind,firstParam,firstIsPointer) GET_PARAM(TYPE_TO_BIND*,1,NO_POINTER)->functionToBind = GET_PARAM(firstParam,2,firstIsPointer) 38 | 39 | #define CALL_FUNCTION_1(type,functionToBind,firstParam,firstIsPointer) type##_1(functionToBind,firstParam,firstIsPointer) 40 | 41 | 42 | #define FUNCTION_2(functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer) functionToBind( GET_PARAM(firstParam,1,firstIsPointer),GET_PARAM(secondParam,2,secondeIsPointer)) 43 | #define METHOD_2(functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer) GET_PARAM(TYPE_TO_BIND*,1,NO_POINTER)->functionToBind( GET_PARAM(firstParam,2,firstIsPointer),GET_PARAM(secondParam,3,secondeIsPointer)) 44 | 45 | #define CALL_FUNCTION_2(type,functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer) type##_2(functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer) 46 | 47 | #define FUNCTION_3(functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer, thirdParam, thirdIsPointer) functionToBind( GET_PARAM(firstParam,1,firstIsPointer),GET_PARAM(secondParam,2,secondeIsPointer),GET_PARAM( thirdParam,3, thirdIsPointer)) 48 | #define METHOD_3(functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer, thirdParam, thirdIsPointer) GET_PARAM(TYPE_TO_BIND*,1,NO_POINTER)->functionToBind( GET_PARAM(firstParam,2,firstIsPointer),GET_PARAM(secondParam,3,secondeIsPointer),GET_PARAM( thirdParam,4, thirdIsPointer)) 49 | 50 | #define CALL_FUNCTION_3(type,functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer, thirdParam, thirdIsPointer) type##_3(functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer, thirdParam, thirdIsPointer) 51 | 52 | 53 | #define DEFAULT_CTOR_1(type,firstParam,firstIsPointer) \ 54 | template<> type* newDefault(lua_State * l) { return new FUNCTION_1(type,firstParam,firstIsPointer) ; } 55 | 56 | #define DEFAULT_CTOR_2(type,firstParam,firstIsPointer,secondParam,secondeIsPointer) \ 57 | template<> type* newDefault(lua_State * l) { return new FUNCTION_2(type,firstParam,firstIsPointer,secondParam,secondeIsPointer) ; } 58 | 59 | #define DEFAULT_CTOR_3(type,firstParam,firstIsPointer,secondParam,secondeIsPointer, thirdParam, thirdIsPointer) \ 60 | template<> type* newDefault(lua_State * l) { return new FUNCTION_3(type,firstParam,firstIsPointer,secondParam,secondeIsPointer, thirdParam, thirdIsPointer) ; } 61 | 62 | #ifdef __GO_FOR_IMPLEMENTATION__ 63 | #define X3(name, type,hasReturn,returnType,functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer, thirdParam, thirdIsPointer) \ 64 | static int BUILD_NAME(NAME_TO_BIND,name) (lua_State * l) { hasReturn(returnType, CALL_FUNCTION_3(type,functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer, thirdParam, thirdIsPointer) ) } 65 | #define X2(name, type,hasReturn,returnType,functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer) \ 66 | static int BUILD_NAME(NAME_TO_BIND,name) (lua_State * l) { hasReturn(returnType, CALL_FUNCTION_2(type,functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer) ) } 67 | #define X1(name, type,hasReturn,returnType,functionToBind,firstParam,firstIsPointer) \ 68 | static int BUILD_NAME(NAME_TO_BIND,name) (lua_State * l) { hasReturn(returnType, CALL_FUNCTION_1(type,functionToBind,firstParam,firstIsPointer) ) } 69 | #define X0(name, type,hasReturn,returnType,functionToBind) \ 70 | static int BUILD_NAME(NAME_TO_BIND,name) (lua_State * l) { hasReturn(returnType, CALL_FUNCTION_0(type,functionToBind) ) } 71 | 72 | #else 73 | #define X3(name, type,hasReturn,returnType,functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer, thirdParam, thirdIsPointer)\ 74 | { #name , BUILD_NAME(NAME_TO_BIND,name) }, 75 | #define X2(name, type,hasReturn,returnType,functionToBind,firstParam,firstIsPointer,secondParam,secondeIsPointer)\ 76 | { #name , BUILD_NAME(NAME_TO_BIND,name) }, 77 | #define X1(name, type,hasReturn,returnType,functionToBind,firstParam, firstIsPointer) \ 78 | { #name , BUILD_NAME(NAME_TO_BIND,name) }, 79 | #define X0(name, type,hasReturn,returnType,functionToBind) \ 80 | { #name , BUILD_NAME(NAME_TO_BIND,name) }, 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/bindingHelper/marco.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __SFLUA__MACRO__ 2 | #define __SFLUA__MACRO__ 3 | 4 | #include "utils.hpp" 5 | 6 | #define LUA_CLASS_NAME(name) const char* name##MetatableName = "luaL_" #name; const char* name##TypeName = #name; 7 | #define IMPLEMENT_LUA_METATABLENAME(name,type) template <> const char* metaTableName() {return name##MetatableName;} 8 | 9 | #define IMPLEMENT_LUA_DEFAULT_CTOR(name,type) int name##_ctor (lua_State * l) { return generic_constructor(l); } 10 | #define IMPLEMENT_LUA_COPY_CTOR(name,type) int name##_copy_ctor(lua_State * l,const type& copy) { return copy_constructor(l,copy); } 11 | #define IMPLEMENT_LUA_DEFAULT_DTOR(name,type) int name##_dtor (lua_State * l) { return destructor(l); } 12 | //define IMPLEMENT_LUA_TYPE_CHECKER(name,type) type* name##_check (lua_State * l,int n) { return check_type(l,n); } 13 | #define IMPLEMENT_LUA_TOSTRING(name,type) int name##_tostring (lua_State * l) { return tostring(l); } 14 | 15 | #define IMPLEMENT_LUA_CLASS(name,type) \ 16 | LUA_CLASS_NAME(name) \ 17 | IMPLEMENT_LUA_METATABLENAME(name,type) \ 18 | IMPLEMENT_LUA_METATABLENAME(name,type*) \ 19 | IMPLEMENT_LUA_DEFAULT_CTOR(name,type) \ 20 | IMPLEMENT_LUA_DEFAULT_DTOR(name,type) \ 21 | IMPLEMENT_LUA_TOSTRING(name,type) 22 | 23 | 24 | #define LUA_BEGIN_REGISTER_CLASS(name) \ 25 | void register_##name(lua_State * l) \ 26 | { \ 27 | luaL_newmetatable(l, name##MetatableName ); \ 28 | luaL_register(l,0, name##_regs); \ 29 | lua_pushvalue(l, -1); \ 30 | lua_setfield(l, -1, "__index"); \ 31 | lua_setglobal(l, name##TypeName); \ 32 | 33 | 34 | #define LUA_END_REGISTER_CLASS \ 35 | } \ 36 | 37 | #define LUA_REGISTER_CLASS(name) \ 38 | LUA_BEGIN_REGISTER_CLASS(name) \ 39 | LUA_END_REGISTER_CLASS 40 | 41 | 42 | #define LUA_DEFAULT_CLASS_FUNC(name) \ 43 | { "new" , name##_ctor }, \ 44 | { "__gc" , name##_dtor }, \ 45 | { "__tostring" , name##_tostring }, \ 46 | 47 | 48 | #define IMPLEMENT_LUA_GENERIC_GETTER(name,type,getType,getname) \ 49 | int name##_get_##getName(lua_State * l) \ 50 | { \ 51 | typpe* obj = check_type(l,1);\ 52 | return 1; \ 53 | } \ 54 | 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/bindingHelper/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.hpp" 2 | 3 | bool test_type(lua_State * l, int n,const char* name) 4 | { 5 | void *p = lua_touserdata(l, n); 6 | if (p != NULL) 7 | { /* value is a userdata? */ 8 | if (lua_getmetatable(l, n)) 9 | { /* does it have a metatable? */ 10 | luaL_getmetatable(l, name); /* get correct metatable */ 11 | if (!lua_rawequal(l, -1, -2)) 12 | { /* not the same? */ 13 | lua_pop(l, 2); /* remove both metatables */ 14 | return false; /* value is a userdata with wrong metatable */ 15 | } 16 | lua_pop(l, 2); /* remove both metatables */ 17 | return true; 18 | } 19 | } 20 | return false; /* value is not a userdata with a metatable */ 21 | } 22 | -------------------------------------------------------------------------------- /src/bindingHelper/utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __SFLUA__UTILS__ 2 | #define __SFLUA__UTILS__ 3 | 4 | #include 5 | 6 | template 7 | T* newDefault(lua_State * l) 8 | { 9 | return new T(); 10 | } 11 | 12 | template 13 | const char* metaTableName() 14 | { 15 | return ""; 16 | } 17 | 18 | template 19 | int generic_constructor(lua_State * l) 20 | { 21 | T ** udata = (T **)lua_newuserdata(l, sizeof(T *)); 22 | *udata = newDefault(l); 23 | luaL_getmetatable(l, metaTableName()); 24 | lua_setmetatable(l, -2); 25 | return 1; 26 | } 27 | 28 | template 29 | int copy_constructor(lua_State * l,const T& copy) 30 | { 31 | T ** udata = (T **)lua_newuserdata(l, sizeof(T *)); 32 | *udata = new T(copy); 33 | luaL_getmetatable(l, metaTableName()); 34 | lua_setmetatable(l, -2); 35 | return 1; 36 | } 37 | 38 | 39 | template 40 | bool test_type(lua_State * l, int n) 41 | { 42 | return test_type(l,n,metaTableName()); 43 | } 44 | 45 | bool test_type(lua_State * l, int n,const char* name); 46 | 47 | template 48 | T* check_type(lua_State * l, int n) 49 | { 50 | return *(T **)luaL_checkudata(l, n, metaTableName()); 51 | } 52 | 53 | template 54 | T check_pointertype(lua_State * l, int n) 55 | { 56 | return *(T *)luaL_checkudata(l, n, metaTableName()); 57 | } 58 | 59 | 60 | template 61 | int destructor(lua_State * l) 62 | { 63 | T* object = check_type(l, 1); 64 | delete object; 65 | return 0; 66 | } 67 | 68 | template 69 | int tostring(lua_State* l) 70 | { 71 | T* object = check_type(l, 1); 72 | printf("%s__0x%llx",metaTableName(),(unsigned long long)object); 73 | return 0; 74 | } 75 | 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/external/graphics/BorderImage.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/src/external/graphics/BorderImage.cpp -------------------------------------------------------------------------------- /src/external/graphics/BorderImage.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canadadry/luaSFML/f55fdd4a269edaa1bc0d118eea1e3f5843ececf6/src/external/graphics/BorderImage.h -------------------------------------------------------------------------------- /src/external/graphics/SGItem.cpp: -------------------------------------------------------------------------------- 1 | #include "SGItem.h" 2 | #include 3 | #include 4 | 5 | 6 | SGItem* SGItem::root = nullptr; 7 | SGItem* SGItem::pickedItem = nullptr; 8 | 9 | 10 | SGItem::SGItem(SGItem* parent,sf::Drawable* content) 11 | : m_width(0.0f) 12 | , m_height(0.0f) 13 | , m_debugContent(nullptr) 14 | , m_content(content) 15 | , m_parentItem(parent) 16 | , m_globalTransform() 17 | { 18 | if(parent == nullptr && root == nullptr) root = this; 19 | if(parent == nullptr) parent = root; 20 | parent->m_childrensItem.push_back(this); 21 | 22 | m_debugContent = new sf::RectangleShape(sf::Vector2f(0,0)); 23 | m_debugContent->setFillColor(sf::Color(std::rand() % 256, std::rand() % 256, std::rand() % 256)); 24 | m_debugContent->setOutlineColor(sf::Color::Black); 25 | m_debugContent->setOutlineThickness(2.0); 26 | 27 | } 28 | 29 | SGItem::~SGItem() 30 | { 31 | for(unsigned int i=0;im_parentItem = nullptr; 34 | } 35 | m_childrensItem.clear(); 36 | 37 | if(m_parentItem != nullptr) 38 | { 39 | std::vector vec = m_parentItem->m_childrensItem; 40 | vec.erase(std::remove(vec.begin(), vec.end(), this), vec.end()); 41 | } 42 | } 43 | 44 | SGItem* SGItem::parentItem() const 45 | { 46 | return m_parentItem; 47 | } 48 | 49 | float SGItem::width()const 50 | { 51 | return m_width; 52 | } 53 | 54 | float SGItem::height()const 55 | { 56 | return m_height; 57 | } 58 | 59 | //sf::Drawable* SGItem::content() const 60 | //{ 61 | // return m_content; 62 | //} 63 | 64 | void SGItem::setWidth(float new_width) { m_width = new_width; } 65 | void SGItem::setHeight(float new_height) { m_height = new_height; } 66 | 67 | void SGItem::draw(sf::RenderTarget& target, sf::RenderStates states) const 68 | { 69 | m_globalTransform = states.transform; 70 | states.transform.combine(getTransform()); 71 | 72 | 73 | m_debugContent->setSize(sf::Vector2f(m_width,m_height)); 74 | target.draw(*m_debugContent,states); 75 | 76 | // if(m_content != NULL) 77 | // { 78 | // target.draw(*m_content,states); 79 | // } 80 | 81 | for(unsigned int i=0;i 0) && (point.y > 0) && (point.x < m_width) && (point.y < m_height); 90 | } 91 | 92 | sf::Vector2f SGItem::mapToItem(const SGItem& finalBasis, sf::Vector2f point) const 93 | { 94 | sf::Vector2f ret; 95 | //1 convert to parent 96 | ret = getTransform().transformPoint(point); 97 | //2 convert coord to root 98 | ret = m_globalTransform.transformPoint(ret); 99 | 100 | // 3 convert to parent of final 101 | ret = finalBasis.m_globalTransform.getInverse().transformPoint(ret); 102 | // 4 and finally to final 103 | ret = finalBasis.getInverseTransform().transformPoint(ret); 104 | return ret; 105 | 106 | } 107 | 108 | sf::Vector2f SGItem::mapFromItem(const SGItem& initialBasis, sf::Vector2f point) const 109 | { 110 | sf::Vector2f ret = point; 111 | ret = initialBasis.getTransform().transformPoint(ret); 112 | ret = initialBasis.m_globalTransform.transformPoint(ret); 113 | ret = m_globalTransform.getInverse().transformPoint(ret); 114 | ret = getInverseTransform().transformPoint(ret); 115 | 116 | return ret; 117 | } 118 | 119 | 120 | void SGItem::pick( sf::Vector2f point) 121 | { 122 | if(pickedItem != nullptr) return; 123 | if(root != nullptr) 124 | { 125 | root->pick(mapToItem(*root,point)); 126 | } 127 | else 128 | { 129 | std::vector pickable; 130 | root->recursivePick(pickable,point); 131 | if(!pickable.empty()) 132 | { 133 | pickedItem = pickable.back(); 134 | pickedItem->m_debugContent->setOutlineColor(sf::Color::Red); 135 | } 136 | } 137 | } 138 | 139 | void SGItem::recursivePick(std::vector& items, sf::Vector2f point) 140 | { 141 | if(containPoint(point)) items.push_back(this); 142 | 143 | for(unsigned int i=0;irecursivePick(items,mapToItem(item,point)); 147 | } 148 | } 149 | 150 | void SGItem::release() 151 | { 152 | pickedItem->m_debugContent->setOutlineColor(sf::Color::Black); 153 | } 154 | 155 | -------------------------------------------------------------------------------- /src/external/graphics/SGItem.h: -------------------------------------------------------------------------------- 1 | #ifndef _SG_ITEM_ 2 | #define _SG_ITEM_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class SGRessource; 14 | 15 | class SGItem :public sf::Drawable, public sf::Transformable 16 | { 17 | 18 | public: 19 | SGItem(SGItem* parent=NULL,sf::Drawable* content=NULL); 20 | virtual ~SGItem(); 21 | 22 | float width()const; 23 | float height()const; 24 | 25 | void setWidth(float new_width); 26 | void setHeight(float new_height); 27 | 28 | sf::Drawable* content() const; 29 | 30 | SGItem* parentItem() const; 31 | 32 | void pick( sf::Vector2f point); 33 | void release(); 34 | 35 | bool containPoint(sf::Vector2f p) const; 36 | sf::Vector2f mapToItem(const SGItem& finalBasis, sf::Vector2f point) const; 37 | sf::Vector2f mapFromItem(const SGItem& initialBasis, sf::Vector2f point) const; 38 | 39 | 40 | protected: 41 | virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const; 42 | 43 | private: 44 | float m_width; 45 | float m_height; 46 | sf::RectangleShape* m_debugContent; 47 | sf::Drawable* m_content; 48 | SGItem* m_parentItem; 49 | std::vector m_childrensItem; 50 | mutable sf::Transform m_globalTransform; 51 | 52 | void updateGlobalTransform(); 53 | 54 | static SGItem* root; 55 | static SGItem* pickedItem; 56 | 57 | void recursivePick(std::vector& items, sf::Vector2f point); 58 | 59 | 60 | }; 61 | 62 | 63 | #endif // endof _SG_ITEM_ 64 | -------------------------------------------------------------------------------- /src/external/graphics/tilemap.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "TileMap.h" 3 | #include 4 | #include 5 | #include 6 | 7 | TileMap::TileMap() 8 | : m_tileset(NULL) 9 | , m_textureWidthInTile(0) 10 | , m_textureHeightInTile(0) 11 | , m_tilemapWidthInTile(0) 12 | , m_tilemapHeightInTile(0) 13 | , m_tileWidthInPixel(0) 14 | , m_tileHeightInPixel(0) 15 | , m_data() 16 | , m_vertex_array(sf::Quads,0) 17 | {} 18 | 19 | 20 | TileMap::~TileMap() 21 | { 22 | } 23 | 24 | void TileMap::setTexture(const sf::Texture& texture) 25 | { 26 | if(m_tileset != &texture) 27 | { 28 | m_tileset = &texture; 29 | if(initTexture()) 30 | { 31 | initTiles(); 32 | } 33 | } 34 | } 35 | 36 | void TileMap::setTileSize(sf::Vector2u tileSize) 37 | { 38 | bool needUpdate = false; 39 | 40 | needUpdate = needUpdate || (tileSize.x != m_tileWidthInPixel); 41 | m_tileWidthInPixel =tileSize.x; 42 | needUpdate = needUpdate || (tileSize.y != m_tileHeightInPixel); 43 | m_tileHeightInPixel = tileSize.y; 44 | if(needUpdate) 45 | { 46 | if(initTexture()) 47 | { 48 | initTiles(); 49 | } 50 | } 51 | 52 | } 53 | 54 | bool TileMap::initTexture() 55 | { 56 | bool ret = false; 57 | if(m_tileset != 0) 58 | { 59 | if(m_tileWidthInPixel != 0 && m_tileHeightInPixel != 0) 60 | { 61 | sf::Vector2u textureSize = m_tileset->getSize(); 62 | unsigned int new_width = textureSize.x /m_tileWidthInPixel; 63 | ret = ret || (new_width != m_textureWidthInTile); 64 | m_textureWidthInTile =new_width; 65 | unsigned int new_height = textureSize.y / m_tileHeightInPixel; 66 | ret = ret || (new_width != m_textureWidthInTile); 67 | m_textureHeightInTile = new_height; 68 | } 69 | } 70 | return ret; 71 | } 72 | 73 | void TileMap::initTiles() 74 | { 75 | if(m_tileset != 0) 76 | { 77 | if(m_tileWidthInPixel != 0 && m_tileHeightInPixel != 0) 78 | { 79 | if(m_textureWidthInTile != 0 && m_textureHeightInTile != 0) 80 | { 81 | for(unsigned int row = 0; rowgetSize().x; 180 | // right /= (float)m_tileset->getSize().x; 181 | // top /= (float)m_tileset->getSize().y; 182 | // bottom /= (float)m_tileset->getSize().y; 183 | // 184 | // left = 0.0; 185 | // right = 1.0; 186 | // top = 0.0; 187 | // bottom = 1.0; 188 | 189 | // printf("textcoord for tile %d (%f,%f,%f,%f) \n",pos,left,right,top,bottom); 190 | 191 | m_vertex_array[pos + 0].texCoords = sf::Vector2f(left, top); 192 | m_vertex_array[pos + 1].texCoords = sf::Vector2f(left, bottom); 193 | m_vertex_array[pos + 2].texCoords = sf::Vector2f(right, bottom); 194 | m_vertex_array[pos + 3].texCoords = sf::Vector2f(right, top); 195 | } 196 | 197 | void TileMap::setTileColor(unsigned int column,unsigned int row) 198 | { 199 | int pos = (column+row*m_tilemapWidthInTile)*4; 200 | 201 | m_vertex_array[pos + 0].color = sf::Color::White; 202 | m_vertex_array[pos + 1].color = sf::Color::White; 203 | m_vertex_array[pos + 2].color = sf::Color::White; 204 | m_vertex_array[pos + 3].color = sf::Color::White; 205 | 206 | } 207 | 208 | void TileMap::draw(sf::RenderTarget& target,sf::RenderStates states) const 209 | { 210 | if (m_tileset) 211 | { 212 | states.transform *= getTransform(); 213 | states.texture = m_tileset; 214 | target.draw(m_vertex_array,states); 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /src/external/graphics/tilemap.h: -------------------------------------------------------------------------------- 1 | #ifndef TILEMAP_H_ 2 | #define TILEMAP_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace sf{ 11 | class Texture; 12 | } 13 | 14 | class TileMap : public sf::Drawable, public sf::Transformable 15 | { 16 | public: 17 | TileMap(); 18 | virtual ~TileMap(); 19 | 20 | void setTexture(const sf::Texture& texture); 21 | void setTileSize(sf::Vector2u tileSize); 22 | 23 | void setIDForTile(unsigned int tileId,unsigned int tileColumn,unsigned int tileRow); 24 | void setIDForTile(unsigned int tileId, sf::Vector2u pos); 25 | int getIDForTile(unsigned int tileColumn,unsigned int tileRow) const; 26 | int getIDForTile(sf::Vector2u pos) const; 27 | 28 | void setData(unsigned int columns,unsigned int rows,const unsigned int* data = 0); 29 | 30 | private: 31 | const sf::Texture* m_tileset; 32 | unsigned int m_textureWidthInTile; 33 | unsigned int m_textureHeightInTile; 34 | unsigned int m_tilemapWidthInTile; 35 | unsigned int m_tilemapHeightInTile; 36 | unsigned int m_tileWidthInPixel; 37 | unsigned int m_tileHeightInPixel; 38 | std::vector m_data; 39 | sf::VertexArray m_vertex_array; 40 | 41 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; 42 | void setTilePosition(unsigned int column,unsigned int row); 43 | void setTileRect(unsigned int column,unsigned int row); 44 | void setTileColor(unsigned int column,unsigned int row); 45 | bool initTexture(); 46 | void initTiles(); 47 | 48 | 49 | inline bool isValidePosition(unsigned int column,unsigned int row) const 50 | { 51 | return row < m_tilemapHeightInTile && column < m_tilemapWidthInTile; 52 | } 53 | 54 | inline unsigned int idFromPosition(unsigned int column,unsigned int row) const 55 | { 56 | return row * m_tilemapWidthInTile + column; 57 | } 58 | 59 | 60 | }; 61 | 62 | #endif /* TILEMAP_H_ */ 63 | -------------------------------------------------------------------------------- /src/external/graphics_wrap/wrap_sgitem.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_sgitem.h" 2 | #include "../../sfml/graphics/wrap_render_window.h" 3 | 4 | #include 5 | 6 | #include "../../bindingHelper/marco.hpp" 7 | #include "../../bindingHelper/lua_template.hpp" 8 | 9 | #include "../../sfml/system/wrap_vector2f.h" 10 | 11 | #define TYPE_TO_BIND SGItem 12 | #define NAME_TO_BIND sfeSGItem 13 | 14 | 15 | 16 | template<> 17 | SGItem* newDefault(lua_State * L) 18 | { 19 | if(lua_gettop(L) >1) 20 | { 21 | return new SGItem(lua_get(L,1)) ; 22 | } 23 | return new SGItem() ; 24 | 25 | } 26 | 27 | IMPLEMENT_LUA_CLASS(sfeSGItem,SGItem) 28 | 29 | #define FUNCTION_TO_BIND \ 30 | X0(parentItem , METHOD ,HAS_RETURN , RET_CTOR , parentItem )\ 31 | X0(width , METHOD ,HAS_RETURN , RET_TYPE( float) , width )\ 32 | X0(height , METHOD ,HAS_RETURN , RET_TYPE( float) , height )\ 33 | X1(setWidth , METHOD , NO_RETURN , RET_NONE , setWidth , float , NO_POINTER )\ 34 | X1(setHeight , METHOD , NO_RETURN , RET_NONE , setHeight , float , NO_POINTER )\ 35 | X1(containPoint , METHOD ,HAS_RETURN , RET_TYPE( bool) , containPoint , sf::Vector2f , IS_POINTER )\ 36 | X2(mapToItem , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , mapToItem , TYPE_TO_BIND , IS_POINTER , sf::Vector2f , IS_POINTER)\ 37 | X2(mapFromItem , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , mapFromItem , TYPE_TO_BIND , IS_POINTER , sf::Vector2f , IS_POINTER)\ 38 | \ 39 | \ 40 | X0(getPosition , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getPosition )\ 41 | X0(getRotation , METHOD ,HAS_RETURN , RET_TYPE( float) , getRotation )\ 42 | X0(getScale , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getScale )\ 43 | X0(getOrigin , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getOrigin )\ 44 | X1(setPosition , METHOD , NO_RETURN , RET_NONE , setPosition , sf::Vector2f , IS_POINTER )\ 45 | X1(setRotation , METHOD , NO_RETURN , RET_NONE , setRotation , float , NO_POINTER )\ 46 | X1(setScale , METHOD , NO_RETURN , RET_NONE , setScale , sf::Vector2f , IS_POINTER )\ 47 | X1(setOrigin , METHOD , NO_RETURN , RET_NONE , setOrigin , sf::Vector2f , IS_POINTER )\ 48 | X1(move , METHOD , NO_RETURN , RET_NONE , move , sf::Vector2f , IS_POINTER )\ 49 | X1(scale , METHOD , NO_RETURN , RET_NONE , scale , sf::Vector2f , IS_POINTER )\ 50 | X1(rotate , METHOD , NO_RETURN , RET_NONE , rotate , float , NO_POINTER )\ 51 | 52 | 53 | #define __GO_FOR_IMPLEMENTATION__ 54 | #include "../../bindingHelper/macro2.hpp" 55 | 56 | FUNCTION_TO_BIND 57 | 58 | #undef __GO_FOR_IMPLEMENTATION__ 59 | #include "../../bindingHelper/macro2.hpp" 60 | 61 | luaL_Reg sfeSGItem_regs[] = 62 | { 63 | LUA_DEFAULT_CLASS_FUNC(sfeSGItem) 64 | FUNCTION_TO_BIND 65 | { NULL, NULL } 66 | }; 67 | 68 | LUA_BEGIN_REGISTER_CLASS(sfeSGItem) 69 | register_drawableType(metaTableName()); 70 | LUA_END_REGISTER_CLASS 71 | -------------------------------------------------------------------------------- /src/external/graphics_wrap/wrap_sgitem.h: -------------------------------------------------------------------------------- 1 | #include "../graphics/SGItem.h" 2 | #include 3 | 4 | void register_sfeSGItem(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | -------------------------------------------------------------------------------- /src/external/graphics_wrap/wrap_tilemap.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_tilemap.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | #include "../../sfml/graphics/wrap_render_window.h" 8 | 9 | #include "../../sfml/graphics/wrap_texture.h" 10 | #include "../../sfml/system/wrap_vector2u.h" 11 | #include "../../sfml/system/wrap_vector2f.h" 12 | 13 | #define TYPE_TO_BIND TileMap 14 | #define NAME_TO_BIND sfeTileMap 15 | 16 | IMPLEMENT_LUA_CLASS(sfeTileMap,TileMap) 17 | 18 | #define FUNCTION_TO_BIND \ 19 | X1(setTexture , METHOD , NO_RETURN , RET_NONE , setTexture , sf::Texture , IS_POINTER )\ 20 | X1(setTileSize , METHOD , NO_RETURN , RET_NONE , setTileSize , sf::Vector2u , IS_POINTER )\ 21 | X2(setIDForTile , METHOD , NO_RETURN , RET_NONE , setIDForTile , unsigned int , NO_POINTER , sf::Vector2u , IS_POINTER)\ 22 | X2(setSize , METHOD , NO_RETURN , RET_NONE , setData , unsigned int , NO_POINTER , unsigned int , NO_POINTER )\ 23 | X1(getIDForTile , METHOD ,HAS_RETURN , RET_TYPE(unsigned int) , getIDForTile , sf::Vector2u , IS_POINTER )\ 24 | \ 25 | \ 26 | X0(getPosition , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getPosition )\ 27 | X0(getRotation , METHOD ,HAS_RETURN , RET_TYPE( float) , getRotation )\ 28 | X0(getScale , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getScale )\ 29 | X0(getOrigin , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getOrigin )\ 30 | X1(setPosition , METHOD , NO_RETURN , RET_NONE , setPosition , sf::Vector2f , IS_POINTER )\ 31 | X1(setRotation , METHOD , NO_RETURN , RET_NONE , setRotation , float , NO_POINTER )\ 32 | X1(setScale , METHOD , NO_RETURN , RET_NONE , setScale , sf::Vector2f , IS_POINTER )\ 33 | X1(setOrigin , METHOD , NO_RETURN , RET_NONE , setOrigin , sf::Vector2f , IS_POINTER )\ 34 | X1(move , METHOD , NO_RETURN , RET_NONE , move , sf::Vector2f , IS_POINTER )\ 35 | X1(scale , METHOD , NO_RETURN , RET_NONE , scale , sf::Vector2f , IS_POINTER )\ 36 | X1(rotate , METHOD , NO_RETURN , RET_NONE , rotate , float , IS_POINTER )\ 37 | 38 | 39 | #define __GO_FOR_IMPLEMENTATION__ 40 | #include "../../bindingHelper/macro2.hpp" 41 | 42 | FUNCTION_TO_BIND 43 | 44 | #undef __GO_FOR_IMPLEMENTATION__ 45 | #include "../../bindingHelper/macro2.hpp" 46 | 47 | luaL_Reg sfeTileMap_regs[] = 48 | { 49 | LUA_DEFAULT_CLASS_FUNC(sfeTileMap) 50 | FUNCTION_TO_BIND 51 | { NULL, NULL } 52 | }; 53 | 54 | 55 | LUA_BEGIN_REGISTER_CLASS(sfeTileMap) 56 | register_drawableType(metaTableName()); 57 | LUA_END_REGISTER_CLASS 58 | 59 | -------------------------------------------------------------------------------- /src/external/graphics_wrap/wrap_tilemap.h: -------------------------------------------------------------------------------- 1 | #include "../graphics/tilemap.h" 2 | #include 3 | 4 | 5 | 6 | void register_sfeTileMap(lua_State * l); 7 | 8 | #include "../../bindingHelper/lua_template.hpp" 9 | template <> 10 | const char* metaTableName(); 11 | 12 | #include "../../bindingHelper/lua_template.hpp" 13 | template <> 14 | const char* metaTableName(); 15 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sfml/sfml.h" 4 | #include "external/graphics_wrap/wrap_tilemap.h" 5 | #include "external/graphics_wrap/wrap_sgitem.h" 6 | //#include "external/physfs/physfsstream.h" 7 | #include 8 | 9 | #ifdef SFML_SYSTEM_WINDOWS 10 | #deinfe EXPORT __declspec(dllexport) 11 | #else 12 | #define EXPORT __attribute__((visibility("default"))) 13 | #endif 14 | 15 | extern "C" EXPORT int luaopen_SFML(lua_State *l) 16 | { 17 | registerSFMLModule(l); 18 | register_sfeTileMap(l); 19 | register_sfeSGItem(l); 20 | return 0; 21 | } 22 | 23 | int main(int argc,char** argv) 24 | { 25 | // printf("Build time %s\n\n",__TIME__); 26 | 27 | if(argc < 2) 28 | { 29 | printf("you must provide a lua file to execute.\n"); 30 | return 0; 31 | } 32 | // chdir(argv[1]); 33 | 34 | // PhysFsStream::init(argv[0]); 35 | // PhysFsStream::addSearchPath("./"); 36 | 37 | lua_State *l = luaL_newstate(); 38 | luaL_openlibs(l); 39 | luaopen_SFML(l); 40 | 41 | luaopen_math(l); 42 | luaopen_os(l); 43 | 44 | if(luaL_dofile(l, argv[1])) printf("Lua error: %s\n",luaL_checkstring(l, -1)); 45 | lua_close(l); 46 | return 1; 47 | } 48 | -------------------------------------------------------------------------------- /src/sfml/audio.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "audio/wrap_music.h" 3 | #include "audio/wrap_sound.h" 4 | #include "audio/wrap_soundbuffer.h" 5 | 6 | void registerAudioModule(lua_State * l) 7 | { 8 | register_MusicEnums(l); 9 | register_SoundEnums(l); 10 | 11 | register_sfMusic(l); 12 | register_sfSoundBuffer(l); 13 | register_sfSound(l); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/sfml/audio.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void registerAudioModule(lua_State * l); 4 | 5 | -------------------------------------------------------------------------------- /src/sfml/audio/wrap_music.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_music.h" 2 | 3 | #include "../../bindingHelper/marco.hpp" 4 | #include "../../bindingHelper/lua_template.hpp" 5 | #include "../../bindingHelper/enum.hpp" 6 | 7 | 8 | #include "../system/wrap_time.h" 9 | 10 | 11 | void register_MusicEnums(lua_State * l) 12 | { 13 | add_enum_to_lua(l,"sfMusicStatus", 14 | "Playing" , sf::Music::Status::Playing, 15 | "Paused" , sf::Music::Status::Paused, 16 | "Stopped" , sf::Music::Status::Stopped, 17 | nullptr); 18 | 19 | } 20 | 21 | 22 | #define TYPE_TO_BIND sf::Music 23 | #define NAME_TO_BIND sfMusic 24 | 25 | IMPLEMENT_LUA_CLASS(sfMusic,sf::Music) 26 | 27 | #define FUNCTION_TO_BIND \ 28 | X1(openFromFile , METHOD ,HAS_RETURN , RET_TYPE(bool) , openFromFile , std::string , NO_POINTER )\ 29 | X0(getDuration , METHOD ,HAS_RETURN , RET_TYPE(sf::Time) , getDuration )\ 30 | X0(play , METHOD ,NO_RETURN , RET_NONE , play )\ 31 | X0(pause , METHOD ,NO_RETURN , RET_NONE , pause)\ 32 | X0(stop , METHOD ,NO_RETURN , RET_NONE , stop )\ 33 | X0(getStatus , METHOD ,HAS_RETURN , RET_TYPE(int) , getStatus )\ 34 | X0(getVolume , METHOD ,HAS_RETURN , RET_TYPE(float) , getVolume )\ 35 | X1(setVolume , METHOD , NO_RETURN , RET_NONE , setVolume , float , NO_POINTER )\ 36 | X0(getLoop , METHOD ,HAS_RETURN , RET_TYPE(bool) , getLoop )\ 37 | X1(setLoop , METHOD , NO_RETURN , RET_NONE , setLoop , bool , NO_POINTER )\ 38 | X0(getPlayingOffset , METHOD ,HAS_RETURN , RET_TYPE(sf::Time) , getPlayingOffset )\ 39 | X1(setPlayingOffset , METHOD , NO_RETURN , RET_NONE , setPlayingOffset , sf::Time , IS_POINTER )\ 40 | 41 | 42 | #define __GO_FOR_IMPLEMENTATION__ 43 | #include "../../bindingHelper/macro2.hpp" 44 | 45 | FUNCTION_TO_BIND 46 | 47 | #undef __GO_FOR_IMPLEMENTATION__ 48 | #include "../../bindingHelper/macro2.hpp" 49 | 50 | luaL_Reg sfMusic_regs[] = 51 | { 52 | LUA_DEFAULT_CLASS_FUNC(sfMusic) 53 | FUNCTION_TO_BIND 54 | { NULL, NULL } 55 | }; 56 | 57 | LUA_REGISTER_CLASS(sfMusic) 58 | -------------------------------------------------------------------------------- /src/sfml/audio/wrap_music.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_MusicEnums(lua_State * l); 5 | 6 | void register_sfMusic(lua_State * l); 7 | 8 | #include "../../bindingHelper/lua_template.hpp" 9 | template <> 10 | const char* metaTableName(); 11 | 12 | #include "../../bindingHelper/lua_template.hpp" 13 | template <> 14 | const char* metaTableName(); 15 | -------------------------------------------------------------------------------- /src/sfml/audio/wrap_sound.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_sound.h" 2 | 3 | 4 | #include "../system/wrap_time.h" 5 | #include "../audio/wrap_soundbuffer.h" 6 | 7 | #include "../../bindingHelper/marco.hpp" 8 | #include "../../bindingHelper/lua_template.hpp" 9 | #include "../../bindingHelper/enum.hpp" 10 | 11 | 12 | void register_SoundEnums(lua_State * l) 13 | { 14 | add_enum_to_lua(l,"sfSoundStatus", 15 | "Playing" , sf::Sound::Status::Playing, 16 | "Paused" , sf::Sound::Status::Paused, 17 | "Stopped" , sf::Sound::Status::Stopped, 18 | nullptr); 19 | 20 | } 21 | 22 | 23 | 24 | #define TYPE_TO_BIND sf::Sound 25 | #define NAME_TO_BIND sfSound 26 | 27 | IMPLEMENT_LUA_CLASS(sfSound,sf::Sound) 28 | 29 | #define FUNCTION_TO_BIND \ 30 | X1(setBuffer , METHOD , NO_RETURN , RET_NONE , setBuffer , sf::SoundBuffer , IS_POINTER )\ 31 | X0(play , METHOD ,NO_RETURN , RET_NONE , play )\ 32 | X0(pause , METHOD ,NO_RETURN , RET_NONE , pause)\ 33 | X0(stop , METHOD ,NO_RETURN , RET_NONE , stop )\ 34 | X0(getStatus , METHOD ,HAS_RETURN , RET_TYPE(int) , getStatus )\ 35 | X0(getVolume , METHOD ,HAS_RETURN , RET_TYPE(float) , getVolume )\ 36 | X1(setVolume , METHOD , NO_RETURN , RET_NONE , setVolume , float , NO_POINTER )\ 37 | X0(getLoop , METHOD ,HAS_RETURN , RET_TYPE(bool) , getLoop )\ 38 | X1(setLoop , METHOD , NO_RETURN , RET_NONE , setLoop , bool , NO_POINTER )\ 39 | X0(getPlayingOffset , METHOD ,HAS_RETURN , RET_TYPE(sf::Time) , getPlayingOffset )\ 40 | X1(setPlayingOffset , METHOD , NO_RETURN , RET_NONE , setPlayingOffset , sf::Time , IS_POINTER )\ 41 | 42 | 43 | #define __GO_FOR_IMPLEMENTATION__ 44 | #include "../../bindingHelper/macro2.hpp" 45 | 46 | FUNCTION_TO_BIND 47 | 48 | #undef __GO_FOR_IMPLEMENTATION__ 49 | #include "../../bindingHelper/macro2.hpp" 50 | 51 | luaL_Reg sfSound_regs[] = 52 | { 53 | LUA_DEFAULT_CLASS_FUNC(sfSound) 54 | FUNCTION_TO_BIND 55 | { NULL, NULL } 56 | }; 57 | 58 | LUA_REGISTER_CLASS(sfSound) 59 | -------------------------------------------------------------------------------- /src/sfml/audio/wrap_sound.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_SoundEnums(lua_State * l); 5 | 6 | void register_sfSound(lua_State * l); 7 | 8 | #include "../../bindingHelper/lua_template.hpp" 9 | template <> 10 | const char* metaTableName(); 11 | 12 | #include "../../bindingHelper/lua_template.hpp" 13 | template <> 14 | const char* metaTableName(); 15 | -------------------------------------------------------------------------------- /src/sfml/audio/wrap_soundbuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_soundbuffer.h" 2 | 3 | #include "../system/wrap_time.h" 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | #define TYPE_TO_BIND sf::SoundBuffer 9 | #define NAME_TO_BIND sfSoundBuffer 10 | 11 | IMPLEMENT_LUA_CLASS(sfSoundBuffer,sf::SoundBuffer) 12 | 13 | #define FUNCTION_TO_BIND \ 14 | X1(loadFromFile , METHOD ,HAS_RETURN , RET_TYPE(bool) , loadFromFile , std::string , NO_POINTER )\ 15 | X0(getDuration , METHOD ,HAS_RETURN , RET_TYPE(sf::Time) , getDuration )\ 16 | 17 | 18 | #define __GO_FOR_IMPLEMENTATION__ 19 | #include "../../bindingHelper/macro2.hpp" 20 | 21 | FUNCTION_TO_BIND 22 | 23 | #undef __GO_FOR_IMPLEMENTATION__ 24 | #include "../../bindingHelper/macro2.hpp" 25 | 26 | luaL_Reg sfSoundBuffer_regs[] = 27 | { 28 | LUA_DEFAULT_CLASS_FUNC(sfSoundBuffer) 29 | FUNCTION_TO_BIND 30 | { NULL, NULL } 31 | }; 32 | 33 | LUA_REGISTER_CLASS(sfSoundBuffer) 34 | -------------------------------------------------------------------------------- /src/sfml/audio/wrap_soundbuffer.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void register_sfSoundBuffer(lua_State * l); 6 | 7 | #include "../../bindingHelper/lua_template.hpp" 8 | template <> 9 | const char* metaTableName(); 10 | 11 | #include "../../bindingHelper/lua_template.hpp" 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/graphics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "graphics/wrap_render_window.h" 3 | #include "graphics/wrap_drawable.h" 4 | #include "graphics/wrap_sprite.h" 5 | #include "graphics/wrap_texture.h" 6 | #include "graphics/wrap_color.h" 7 | #include "graphics/wrap_float_rect.h" 8 | #include "graphics/wrap_int_rect.h" 9 | #include "graphics/wrap_font.h" 10 | #include "graphics/wrap_text.h" 11 | #include "graphics/wrap_circle_shape.h" 12 | #include "graphics/wrap_rectangle_shape.h" 13 | 14 | void registerGraphicsModule(lua_State * l) 15 | { 16 | register_TextEnums(l); 17 | 18 | register_sfRenderWindow(l); 19 | register_sfDrawable(l); 20 | register_sfSprite(l); 21 | register_sfTexture(l); 22 | register_sfColor(l); 23 | register_sfFloatRect(l); 24 | register_sfIntRect(l); 25 | register_sfFont(l); 26 | register_sfText(l); 27 | register_sfCircleShape(l); 28 | register_sfRectangleShape(l); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/sfml/graphics.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void registerGraphicsModule(lua_State * l); 4 | 5 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_circle_shape.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_circle_shape.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | #include "../graphics/wrap_color.h" 8 | #include "../graphics/wrap_texture.h" 9 | #include "../graphics/wrap_int_rect.h" 10 | #include "../graphics/wrap_float_rect.h" 11 | #include "../system/wrap_vector2f.h" 12 | #include "../graphics/wrap_render_window.h" 13 | 14 | #define TYPE_TO_BIND sf::CircleShape 15 | #define NAME_TO_BIND sfCircleShape 16 | 17 | #include "../../bindingHelper/macro2.hpp" 18 | DEFAULT_CTOR_1(sf::CircleShape,float,NO_POINTER) 19 | 20 | IMPLEMENT_LUA_CLASS(sfCircleShape,sf::CircleShape) 21 | 22 | #define FUNCTION_TO_BIND \ 23 | X1(setPointCount , METHOD , NO_RETURN , RET_NONE , setPointCount , unsigned int , NO_POINTER )\ 24 | X1(setOutlineThickness , METHOD , NO_RETURN , RET_NONE , setOutlineThickness , float , NO_POINTER )\ 25 | X1(setRadius , METHOD , NO_RETURN , RET_NONE , setRadius , float , NO_POINTER )\ 26 | X1(setFillColor , METHOD , NO_RETURN , RET_NONE , setFillColor , sf::Color , IS_POINTER )\ 27 | X1(setOutlineColor , METHOD , NO_RETURN , RET_NONE , setOutlineColor , sf::Color , IS_POINTER )\ 28 | X1(setTextureRect , METHOD , NO_RETURN , RET_NONE , setTextureRect , sf::IntRect , IS_POINTER )\ 29 | X0(getPointCount , METHOD ,HAS_RETURN , RET_TYPE(unsigned int ) , getPointCount )\ 30 | X0(getOutlineThickness , METHOD ,HAS_RETURN , RET_TYPE(float ) , getOutlineThickness )\ 31 | X0(getRadius , METHOD ,HAS_RETURN , RET_TYPE(float ) , getRadius )\ 32 | X0(getFillColor , METHOD ,HAS_RETURN , RET_TYPE(sf::Color ) , getFillColor )\ 33 | X0(getOutlineColor , METHOD ,HAS_RETURN , RET_TYPE(sf::Color ) , getOutlineColor )\ 34 | X0(getTextureRect , METHOD ,HAS_RETURN , RET_TYPE(sf::IntRect ) , getTextureRect )\ 35 | X0(getLocalBounds , METHOD ,HAS_RETURN , RET_TYPE(sf::FloatRect) , getLocalBounds )\ 36 | X0(getGlobalBounds , METHOD ,HAS_RETURN , RET_TYPE(sf::FloatRect) , getGlobalBounds )\ 37 | \ 38 | \ 39 | X0(getPosition , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getPosition )\ 40 | X0(getRotation , METHOD ,HAS_RETURN , RET_TYPE( float) , getRotation )\ 41 | X0(getScale , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getScale )\ 42 | X0(getOrigin , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getOrigin )\ 43 | X1(setPosition , METHOD , NO_RETURN , RET_NONE , setPosition , sf::Vector2f , IS_POINTER )\ 44 | X1(setRotation , METHOD , NO_RETURN , RET_NONE , setRotation , float , NO_POINTER )\ 45 | X1(setScale , METHOD , NO_RETURN , RET_NONE , setScale , sf::Vector2f , IS_POINTER )\ 46 | X1(setOrigin , METHOD , NO_RETURN , RET_NONE , setOrigin , sf::Vector2f , IS_POINTER )\ 47 | X1(move , METHOD , NO_RETURN , RET_NONE , move , sf::Vector2f , IS_POINTER )\ 48 | X1(scale , METHOD , NO_RETURN , RET_NONE , scale , sf::Vector2f , IS_POINTER )\ 49 | X1(rotate , METHOD , NO_RETURN , RET_NONE , rotate , float , IS_POINTER )\ 50 | 51 | 52 | #define __GO_FOR_IMPLEMENTATION__ 53 | #include "../../bindingHelper/macro2.hpp" 54 | 55 | FUNCTION_TO_BIND 56 | 57 | #undef __GO_FOR_IMPLEMENTATION__ 58 | #include "../../bindingHelper/macro2.hpp" 59 | 60 | luaL_Reg sfCircleShape_regs[] = 61 | { 62 | LUA_DEFAULT_CLASS_FUNC(sfCircleShape) 63 | FUNCTION_TO_BIND 64 | { NULL, NULL } 65 | }; 66 | 67 | LUA_BEGIN_REGISTER_CLASS(sfCircleShape) 68 | register_drawableType(metaTableName()); 69 | LUA_END_REGISTER_CLASS 70 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_circle_shape.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void register_sfCircleShape(lua_State * l); 6 | 7 | #include "../../bindingHelper/lua_template.hpp" 8 | template <> 9 | const char* metaTableName(); 10 | 11 | #include "../../bindingHelper/lua_template.hpp" 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_color.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_color.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | #define TYPE_TO_BIND sf::Color 9 | #define NAME_TO_BIND sfColor 10 | 11 | #include "../../bindingHelper/macro2.hpp" 12 | 13 | DEFAULT_CTOR_3(sf::Color,unsigned char,NO_POINTER,unsigned char,NO_POINTER,unsigned char,NO_POINTER) 14 | 15 | IMPLEMENT_LUA_CLASS(sfColor,sf::Color) 16 | 17 | #define FUNCTION_TO_BIND \ 18 | X1(setR , SETTER ,NO_RETURN , RET_NONE , r , unsigned char , NO_POINTER )\ 19 | X1(setG , SETTER ,NO_RETURN , RET_NONE , g , unsigned char , NO_POINTER )\ 20 | X1(setB , SETTER ,NO_RETURN , RET_NONE , b , unsigned char , NO_POINTER )\ 21 | X1(setA , SETTER ,NO_RETURN , RET_NONE , a , unsigned char , NO_POINTER )\ 22 | X0(r , GETTER ,HAS_RETURN , RET_TYPE(unsigned char) , r )\ 23 | X0(g , GETTER ,HAS_RETURN , RET_TYPE(unsigned char) , g )\ 24 | X0(b , GETTER ,HAS_RETURN , RET_TYPE(unsigned char) , b )\ 25 | X0(a , GETTER ,HAS_RETURN , RET_TYPE(unsigned char) , a )\ 26 | X2(__mul , FUNCTION ,HAS_RETURN , RET_CTOR , operator* , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 27 | X2(__add , FUNCTION ,HAS_RETURN , RET_CTOR , operator+ , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 28 | X2(__eq , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator== , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 29 | 30 | 31 | #define __GO_FOR_IMPLEMENTATION__ 32 | #include "../../bindingHelper/macro2.hpp" 33 | 34 | FUNCTION_TO_BIND 35 | 36 | #undef __GO_FOR_IMPLEMENTATION__ 37 | #include "../../bindingHelper/macro2.hpp" 38 | 39 | luaL_Reg sfColor_regs[] = 40 | { 41 | LUA_DEFAULT_CLASS_FUNC(sfColor) 42 | FUNCTION_TO_BIND 43 | { NULL, NULL } 44 | }; 45 | 46 | LUA_REGISTER_CLASS(sfColor) 47 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_color.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfColor(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_drawable.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_drawable.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | template <> 9 | sf::Drawable* newDefault(lua_State * l) 10 | { 11 | luaL_error(l,"cannot instanciate sfDrawable directly"); 12 | return nullptr; 13 | } 14 | 15 | #define TYPE_TO_BIND sf::Drawable 16 | #define NAME_TO_BIND sfDrawable 17 | 18 | IMPLEMENT_LUA_CLASS(sfDrawable,sf::Drawable) 19 | 20 | #define FUNCTION_TO_BIND \ 21 | // define your function here 22 | 23 | #define __GO_FOR_IMPLEMENTATION__ 24 | #include "../../bindingHelper/macro2.hpp" 25 | 26 | FUNCTION_TO_BIND 27 | 28 | #undef __GO_FOR_IMPLEMENTATION__ 29 | #include "../../bindingHelper/macro2.hpp" 30 | 31 | luaL_Reg sfDrawable_regs[] = 32 | { 33 | LUA_DEFAULT_CLASS_FUNC(sfDrawable) 34 | FUNCTION_TO_BIND 35 | { NULL, NULL } 36 | }; 37 | 38 | LUA_REGISTER_CLASS(sfDrawable) 39 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_drawable.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfDrawable(lua_State * l); 5 | 6 | 7 | #include "../../bindingHelper/lua_template.hpp" 8 | template <> 9 | const char* metaTableName(); 10 | 11 | #include "../../bindingHelper/lua_template.hpp" 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_float_rect.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_int_rect.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | #include "../system/wrap_vector2f.h" 9 | 10 | #define TYPE_TO_BIND sf::FloatRect 11 | #define NAME_TO_BIND sfFloatRect 12 | 13 | #include "../../bindingHelper/macro2.hpp" 14 | 15 | DEFAULT_CTOR_2(sf::FloatRect,sf::Vector2f,IS_POINTER,sf::Vector2f,IS_POINTER) 16 | 17 | IMPLEMENT_LUA_CLASS(sfFloatRect,sf::FloatRect) 18 | 19 | #define FUNCTION_TO_BIND \ 20 | X2(__eq , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator== , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 21 | X1(contains , METHOD ,HAS_RETURN , RET_TYPE(bool) , contains , sf::Vector2f , IS_POINTER )\ 22 | X1(intersects , METHOD ,HAS_RETURN , RET_TYPE(bool) , intersects , TYPE_TO_BIND , IS_POINTER )\ 23 | X1(setLeft , SETTER ,NO_RETURN , RET_NONE , left , float , NO_POINTER )\ 24 | X1(setTop , SETTER ,NO_RETURN , RET_NONE , top , float , NO_POINTER )\ 25 | X1(setWidth , SETTER ,NO_RETURN , RET_NONE , width , float , NO_POINTER )\ 26 | X1(setHeight , SETTER ,NO_RETURN , RET_NONE , height , float , NO_POINTER )\ 27 | X0(left , GETTER ,HAS_RETURN , RET_TYPE(float) , left )\ 28 | X0(top , GETTER ,HAS_RETURN , RET_TYPE(float) , top )\ 29 | X0(width , GETTER ,HAS_RETURN , RET_TYPE(float) , width )\ 30 | X0(height , GETTER ,HAS_RETURN , RET_TYPE(float) , height )\ 31 | 32 | 33 | #define __GO_FOR_IMPLEMENTATION__ 34 | #include "../../bindingHelper/macro2.hpp" 35 | 36 | FUNCTION_TO_BIND 37 | 38 | #undef __GO_FOR_IMPLEMENTATION__ 39 | #include "../../bindingHelper/macro2.hpp" 40 | 41 | luaL_Reg sfFloatRect_regs[] = 42 | { 43 | LUA_DEFAULT_CLASS_FUNC(sfFloatRect) 44 | FUNCTION_TO_BIND 45 | { NULL, NULL } 46 | }; 47 | 48 | LUA_REGISTER_CLASS(sfFloatRect) 49 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_float_rect.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfFloatRect(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_font.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_font.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | 9 | #define TYPE_TO_BIND sf::Font 10 | #define NAME_TO_BIND sfFont 11 | 12 | IMPLEMENT_LUA_CLASS(sfFont,sf::Font) 13 | 14 | #define FUNCTION_TO_BIND \ 15 | X1(loadFromFile , METHOD ,HAS_RETURN , RET_TYPE(bool) , loadFromFile , std::string , NO_POINTER )\ 16 | 17 | #define __GO_FOR_IMPLEMENTATION__ 18 | #include "../../bindingHelper/macro2.hpp" 19 | 20 | FUNCTION_TO_BIND 21 | 22 | #undef __GO_FOR_IMPLEMENTATION__ 23 | #include "../../bindingHelper/macro2.hpp" 24 | 25 | luaL_Reg sfFont_regs[] = 26 | { 27 | LUA_DEFAULT_CLASS_FUNC(sfFont) 28 | FUNCTION_TO_BIND 29 | { NULL, NULL } 30 | }; 31 | 32 | LUA_REGISTER_CLASS(sfFont) 33 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_font.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfFont(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_int_rect.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_int_rect.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | #include "../system/wrap_vector2i.h" 9 | 10 | #define TYPE_TO_BIND sf::IntRect 11 | #define NAME_TO_BIND sfIntRect 12 | 13 | #include "../../bindingHelper/macro2.hpp" 14 | 15 | DEFAULT_CTOR_2(sf::IntRect,sf::Vector2i,IS_POINTER,sf::Vector2i,IS_POINTER) 16 | 17 | IMPLEMENT_LUA_CLASS(sfIntRect,sf::IntRect) 18 | 19 | #define FUNCTION_TO_BIND \ 20 | X2(__eq , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator== , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 21 | X1(contains , METHOD ,HAS_RETURN , RET_TYPE(bool) , contains , sf::Vector2i , IS_POINTER )\ 22 | X1(intersects , METHOD ,HAS_RETURN , RET_TYPE(bool) , intersects , TYPE_TO_BIND , IS_POINTER )\ 23 | X1(setLeft , SETTER ,NO_RETURN , RET_NONE , left , int , NO_POINTER )\ 24 | X1(setTop , SETTER ,NO_RETURN , RET_NONE , top , int , NO_POINTER )\ 25 | X1(setWidth , SETTER ,NO_RETURN , RET_NONE , width , int , NO_POINTER )\ 26 | X1(setHeight , SETTER ,NO_RETURN , RET_NONE , height , int , NO_POINTER )\ 27 | X0(left , GETTER ,HAS_RETURN , RET_TYPE(int) , left )\ 28 | X0(top , GETTER ,HAS_RETURN , RET_TYPE(int) , top )\ 29 | X0(width , GETTER ,HAS_RETURN , RET_TYPE(int) , width )\ 30 | X0(height , GETTER ,HAS_RETURN , RET_TYPE(int) , height )\ 31 | 32 | 33 | #define __GO_FOR_IMPLEMENTATION__ 34 | #include "../../bindingHelper/macro2.hpp" 35 | 36 | FUNCTION_TO_BIND 37 | 38 | #undef __GO_FOR_IMPLEMENTATION__ 39 | #include "../../bindingHelper/macro2.hpp" 40 | 41 | luaL_Reg sfIntRect_regs[] = 42 | { 43 | LUA_DEFAULT_CLASS_FUNC(sfIntRect) 44 | FUNCTION_TO_BIND 45 | { NULL, NULL } 46 | }; 47 | 48 | LUA_REGISTER_CLASS(sfIntRect) 49 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_int_rect.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfIntRect(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_rectangle_shape.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_rectangle_shape.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | #include "../graphics/wrap_color.h" 8 | #include "../graphics/wrap_texture.h" 9 | #include "../graphics/wrap_int_rect.h" 10 | #include "../graphics/wrap_float_rect.h" 11 | #include "../system/wrap_vector2f.h" 12 | #include "../graphics/wrap_render_window.h" 13 | 14 | 15 | #define TYPE_TO_BIND sf::RectangleShape 16 | #define NAME_TO_BIND sfRectangleShape 17 | 18 | #include "../../bindingHelper/macro2.hpp" 19 | DEFAULT_CTOR_1(sf::RectangleShape,sf::Vector2f,IS_POINTER) 20 | 21 | IMPLEMENT_LUA_CLASS(sfRectangleShape,sf::RectangleShape) 22 | 23 | #define FUNCTION_TO_BIND \ 24 | X1(setOutlineThickness , METHOD , NO_RETURN , RET_NONE , setOutlineThickness , float , NO_POINTER )\ 25 | X1(setSize , METHOD , NO_RETURN , RET_NONE , setSize , sf::Vector2f , IS_POINTER )\ 26 | X1(setFillColor , METHOD , NO_RETURN , RET_NONE , setFillColor , sf::Color , IS_POINTER )\ 27 | X1(setOutlineColor , METHOD , NO_RETURN , RET_NONE , setOutlineColor , sf::Color , IS_POINTER )\ 28 | X1(setTextureRect , METHOD , NO_RETURN , RET_NONE , setTextureRect , sf::IntRect , IS_POINTER )\ 29 | X0(getOutlineThickness , METHOD ,HAS_RETURN , RET_TYPE(float ) , getOutlineThickness )\ 30 | X0(getSize , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f ) , getSize )\ 31 | X0(getFillColor , METHOD ,HAS_RETURN , RET_TYPE(sf::Color ) , getFillColor )\ 32 | X0(getOutlineColor , METHOD ,HAS_RETURN , RET_TYPE(sf::Color ) , getOutlineColor )\ 33 | X0(getTextureRect , METHOD ,HAS_RETURN , RET_TYPE(sf::IntRect ) , getTextureRect )\ 34 | X0(getLocalBounds , METHOD ,HAS_RETURN , RET_TYPE(sf::FloatRect) , getLocalBounds )\ 35 | X0(getGlobalBounds , METHOD ,HAS_RETURN , RET_TYPE(sf::FloatRect) , getGlobalBounds )\ 36 | \ 37 | \ 38 | X0(getPosition , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getPosition )\ 39 | X0(getRotation , METHOD ,HAS_RETURN , RET_TYPE( float) , getRotation )\ 40 | X0(getScale , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getScale )\ 41 | X0(getOrigin , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getOrigin )\ 42 | X1(setPosition , METHOD , NO_RETURN , RET_NONE , setPosition , sf::Vector2f , IS_POINTER )\ 43 | X1(setRotation , METHOD , NO_RETURN , RET_NONE , setRotation , float , NO_POINTER )\ 44 | X1(setScale , METHOD , NO_RETURN , RET_NONE , setScale , sf::Vector2f , IS_POINTER )\ 45 | X1(setOrigin , METHOD , NO_RETURN , RET_NONE , setOrigin , sf::Vector2f , IS_POINTER )\ 46 | X1(move , METHOD , NO_RETURN , RET_NONE , move , sf::Vector2f , IS_POINTER )\ 47 | X1(scale , METHOD , NO_RETURN , RET_NONE , scale , sf::Vector2f , IS_POINTER )\ 48 | X1(rotate , METHOD , NO_RETURN , RET_NONE , rotate , float , IS_POINTER )\ 49 | 50 | 51 | #define __GO_FOR_IMPLEMENTATION__ 52 | #include "../../bindingHelper/macro2.hpp" 53 | 54 | FUNCTION_TO_BIND 55 | 56 | #undef __GO_FOR_IMPLEMENTATION__ 57 | #include "../../bindingHelper/macro2.hpp" 58 | 59 | luaL_Reg sfRectangleShape_regs[] = 60 | { 61 | LUA_DEFAULT_CLASS_FUNC(sfRectangleShape) 62 | FUNCTION_TO_BIND 63 | { NULL, NULL } 64 | }; 65 | 66 | LUA_BEGIN_REGISTER_CLASS(sfRectangleShape) 67 | register_drawableType(metaTableName()); 68 | LUA_END_REGISTER_CLASS 69 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_rectangle_shape.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void register_sfRectangleShape(lua_State * l); 6 | 7 | #include "../../bindingHelper/lua_template.hpp" 8 | template <> 9 | const char* metaTableName(); 10 | 11 | #include "../../bindingHelper/lua_template.hpp" 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_render_window.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_render_window.h" 2 | #include 3 | #include 4 | 5 | #define TYPE_TO_BIND sf::RenderWindow 6 | #define NAME_TO_BIND sfRenderWindow 7 | 8 | #include "../../bindingHelper/marco.hpp" 9 | #include "../../bindingHelper/macro2.hpp" 10 | #include "../../bindingHelper/lua_template.hpp" 11 | #include "../../bindingHelper/enum.hpp" 12 | 13 | #include "../system/wrap_vector2i.h" 14 | #include "../system/wrap_vector2u.h" 15 | #include "../window/wrap_event.h" 16 | #include "../window/wrap_videomode.h" 17 | #include "../graphics/wrap_sprite.h" 18 | #include "../graphics/wrap_text.h" 19 | #include "../graphics/wrap_color.h" 20 | #include "../graphics/wrap_circle_shape.h" 21 | #include "../graphics/wrap_rectangle_shape.h" 22 | 23 | DEFAULT_CTOR_3(sf::RenderWindow,sf::VideoMode,IS_POINTER,std::string,NO_POINTER,unsigned int,NO_POINTER) 24 | 25 | IMPLEMENT_LUA_CLASS(sfRenderWindow,sf::RenderWindow) 26 | 27 | #define FUNCTION_TO_BIND \ 28 | X0(isOpen , METHOD , HAS_RETURN , RET_TYPE(bool) , isOpen ) \ 29 | X0(close , METHOD , NO_RETURN , RET_NONE , close ) \ 30 | X0(display , METHOD , NO_RETURN , RET_NONE , display ) \ 31 | X0(getPosition , METHOD , HAS_RETURN , RET_TYPE(sf::Vector2i) , getPosition ) \ 32 | X1(setPosition , METHOD ,NO_RETURN , RET_NONE , setPosition , sf::Vector2i , IS_POINTER )\ 33 | X0(getSize , METHOD , HAS_RETURN , RET_TYPE(sf::Vector2u) , getSize ) \ 34 | X1(setSize , METHOD ,NO_RETURN , RET_NONE , setSize , sf::Vector2u , IS_POINTER )\ 35 | X1(setTitle , METHOD ,NO_RETURN , RET_NONE , setTitle , std::string , NO_POINTER )\ 36 | X1(setVisible , METHOD ,NO_RETURN , RET_NONE , setVisible , bool , NO_POINTER )\ 37 | X1(setVerticalSyncEnabled , METHOD ,NO_RETURN , RET_NONE , setVerticalSyncEnabled , bool , NO_POINTER )\ 38 | X1(setMouseCursorVisible , METHOD ,NO_RETURN , RET_NONE , setMouseCursorVisible , bool , NO_POINTER )\ 39 | X1(setKeyRepeatEnabled , METHOD ,NO_RETURN , RET_NONE , setKeyRepeatEnabled , bool , NO_POINTER )\ 40 | X1(setJoystickThreshold , METHOD ,NO_RETURN , RET_NONE , setJoystickThreshold , bool , NO_POINTER )\ 41 | X1(setActive , METHOD ,NO_RETURN , RET_NONE , setActive , bool , NO_POINTER )\ 42 | X1(setFramerateLimit , METHOD ,NO_RETURN , RET_NONE , setFramerateLimit , unsigned int , NO_POINTER )\ 43 | X1(pollEvent , METHOD ,HAS_RETURN , RET_TYPE(bool) , pollEvent , sf::Event , IS_POINTER )\ 44 | X1(waitEvent , METHOD ,HAS_RETURN , RET_TYPE(bool) , waitEvent , sf::Event , IS_POINTER )\ 45 | X3(create , METHOD , NO_RETURN , RET_NONE , create , sf::VideoMode , IS_POINTER , std::string , NO_POINTER, unsigned int , NO_POINTER)\ 46 | \ 47 | X1(clear , METHOD , NO_RETURN , RET_NONE , clear ,sf::Color, IS_POINTER ) \ 48 | 49 | //X1(draw , METHOD , NO_RETURN , RET_NONE , draw , sf::Drawable, IS_POINTER) \ 50 | 51 | #define __GO_FOR_IMPLEMENTATION__ 52 | #include "../../bindingHelper/macro2.hpp" 53 | 54 | FUNCTION_TO_BIND 55 | 56 | #undef __GO_FOR_IMPLEMENTATION__ 57 | #include "../../bindingHelper/macro2.hpp" 58 | 59 | int sfRenderWindow_draw(lua_State* l); 60 | 61 | luaL_Reg sfRenderWindow_regs[] = 62 | { 63 | LUA_DEFAULT_CLASS_FUNC(sfRenderWindow) 64 | FUNCTION_TO_BIND 65 | {"draw" , sfRenderWindow_draw}, 66 | { NULL, NULL } 67 | }; 68 | 69 | LUA_REGISTER_CLASS(sfRenderWindow) 70 | 71 | static std::vector drawableType; 72 | 73 | 74 | int sfRenderWindow_draw(lua_State* l) 75 | { 76 | fflush(stdout); 77 | sf::Drawable* obj = nullptr; 78 | for(int i= 0; i< drawableType.size();i++) 79 | { 80 | if(test_type(l,2,drawableType[i].c_str())) 81 | { 82 | obj = *(sf::Drawable**) luaL_checkudata(l, 2, drawableType[i].c_str()); 83 | break; 84 | } 85 | } 86 | if(obj ==nullptr) 87 | { 88 | luaL_argerror(l,2,"sfDrawable expected"); 89 | } 90 | else 91 | { 92 | lua_get(l,1)->draw(*obj); 93 | } 94 | return 0; 95 | } 96 | 97 | 98 | void register_drawableType(const char* name) 99 | { 100 | drawableType.push_back(std::string(name)); 101 | } 102 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_render_window.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | 6 | void register_sfRenderWindow(lua_State * l); 7 | 8 | void register_drawableType(const char* name); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | 14 | #include "../../bindingHelper/lua_template.hpp" 15 | template <> 16 | const char* metaTableName(); 17 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_sprite.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_sprite.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | #include "../graphics/wrap_render_window.h" 9 | #include "../graphics/wrap_color.h" 10 | #include "../graphics/wrap_texture.h" 11 | #include "../graphics/wrap_int_rect.h" 12 | #include "../graphics/wrap_float_rect.h" 13 | #include "../system/wrap_vector2f.h" 14 | 15 | #define TYPE_TO_BIND sf::Sprite 16 | #define NAME_TO_BIND sfSprite 17 | 18 | #include "../../bindingHelper/macro2.hpp" 19 | DEFAULT_CTOR_1(sf::Sprite,sf::Texture,IS_POINTER) 20 | 21 | IMPLEMENT_LUA_CLASS(sfSprite,sf::Sprite) 22 | 23 | #define FUNCTION_TO_BIND \ 24 | X1(setTexture , METHOD , NO_RETURN , RET_NONE , setTexture , sf::Texture , IS_POINTER )\ 25 | X1(setColor , METHOD , NO_RETURN , RET_NONE , setColor , sf::Color , IS_POINTER )\ 26 | X1(setTextureRect , METHOD , NO_RETURN , RET_NONE , setTextureRect , sf::IntRect , IS_POINTER )\ 27 | X0(getLocalBounds , METHOD ,HAS_RETURN , RET_TYPE(sf::FloatRect) , getLocalBounds )\ 28 | X0(getGlobalBounds , METHOD ,HAS_RETURN , RET_TYPE(sf::FloatRect) , getGlobalBounds )\ 29 | \ 30 | \ 31 | X0(getPosition , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getPosition )\ 32 | X0(getRotation , METHOD ,HAS_RETURN , RET_TYPE( float) , getRotation )\ 33 | X0(getScale , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getScale )\ 34 | X0(getOrigin , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getOrigin )\ 35 | X1(setPosition , METHOD , NO_RETURN , RET_NONE , setPosition , sf::Vector2f , IS_POINTER )\ 36 | X1(setRotation , METHOD , NO_RETURN , RET_NONE , setRotation , float , NO_POINTER )\ 37 | X1(setScale , METHOD , NO_RETURN , RET_NONE , setScale , sf::Vector2f , IS_POINTER )\ 38 | X1(setOrigin , METHOD , NO_RETURN , RET_NONE , setOrigin , sf::Vector2f , IS_POINTER )\ 39 | X1(move , METHOD , NO_RETURN , RET_NONE , move , sf::Vector2f , IS_POINTER )\ 40 | X1(scale , METHOD , NO_RETURN , RET_NONE , scale , sf::Vector2f , IS_POINTER )\ 41 | X1(rotate , METHOD , NO_RETURN , RET_NONE , rotate , float , IS_POINTER )\ 42 | 43 | 44 | #define __GO_FOR_IMPLEMENTATION__ 45 | #include "../../bindingHelper/macro2.hpp" 46 | 47 | FUNCTION_TO_BIND 48 | 49 | #undef __GO_FOR_IMPLEMENTATION__ 50 | #include "../../bindingHelper/macro2.hpp" 51 | 52 | 53 | luaL_Reg sfSprite_regs[] = 54 | { 55 | LUA_DEFAULT_CLASS_FUNC(sfSprite) 56 | FUNCTION_TO_BIND 57 | { NULL, NULL } 58 | }; 59 | 60 | LUA_BEGIN_REGISTER_CLASS(sfSprite) 61 | register_drawableType(metaTableName()); 62 | LUA_END_REGISTER_CLASS 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_sprite.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfSprite(lua_State * l); 5 | 6 | 7 | #include "../../bindingHelper/lua_template.hpp" 8 | template <> 9 | const char* metaTableName(); 10 | 11 | #include "../../bindingHelper/lua_template.hpp" 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_text.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_text.h" 2 | #include "wrap_font.h" 3 | 4 | #include 5 | 6 | #include 7 | #include "../../bindingHelper/marco.hpp" 8 | #include "../../bindingHelper/lua_template.hpp" 9 | #include "../../bindingHelper/enum.hpp" 10 | 11 | void register_TextEnums(lua_State * l) 12 | { 13 | add_enum_to_lua(l,"sfTextStyle", 14 | "Regular" , sf::Text::Regular, 15 | "Bold" , sf::Text::Bold, 16 | "Italic" , sf::Text::Italic, 17 | "Underlined" , sf::Text::Underlined, 18 | nullptr); 19 | 20 | } 21 | 22 | 23 | #define TYPE_TO_BIND sf::Text 24 | #define NAME_TO_BIND sfText 25 | 26 | #include "../../bindingHelper/macro2.hpp" 27 | #include "../graphics/wrap_render_window.h" 28 | #include "../graphics/wrap_font.h" 29 | #include "../graphics/wrap_color.h" 30 | #include "../system/wrap_vector2f.h" 31 | #include "../graphics/wrap_float_rect.h" 32 | 33 | DEFAULT_CTOR_3(sf::Text,std::string,NO_POINTER,sf::Font,IS_POINTER,unsigned int,NO_POINTER) 34 | 35 | IMPLEMENT_LUA_CLASS(sfText,sf::Text) 36 | 37 | #define FUNCTION_TO_BIND \ 38 | X1(setStyle , METHOD , NO_RETURN , RET_NONE , setStyle , unsigned int , NO_POINTER )\ 39 | X1(setFont , METHOD , NO_RETURN , RET_NONE , setFont , sf::Font , IS_POINTER )\ 40 | X1(setColor , METHOD , NO_RETURN , RET_NONE , setColor , sf::Color , IS_POINTER )\ 41 | X1(setString , METHOD , NO_RETURN , RET_NONE , setString , std::string , NO_POINTER )\ 42 | X1(setCharacterSize , METHOD , NO_RETURN , RET_NONE , setCharacterSize , unsigned int , NO_POINTER )\ 43 | X0(getStyle , METHOD ,HAS_RETURN , RET_TYPE(unsigned int) , getStyle )\ 44 | X0(getColor , METHOD ,HAS_RETURN , RET_TYPE(sf::Color ) , getColor )\ 45 | X0(getString , METHOD ,HAS_RETURN , RET_TYPE(std::string ) , getString )\ 46 | X0(getCharacterSize , METHOD , NO_RETURN , RET_TYPE(unsigned int) , getCharacterSize )\ 47 | X0(getLocalBounds , METHOD ,HAS_RETURN , RET_TYPE(sf::FloatRect) , getLocalBounds )\ 48 | X0(getGlobalBounds , METHOD ,HAS_RETURN , RET_TYPE(sf::FloatRect) , getGlobalBounds )\ 49 | \ 50 | \ 51 | X0(getPosition , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getPosition )\ 52 | X0(getRotation , METHOD ,HAS_RETURN , RET_TYPE( float) , getRotation )\ 53 | X0(getScale , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getScale )\ 54 | X0(getOrigin , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2f) , getOrigin )\ 55 | X1(setPosition , METHOD , NO_RETURN , RET_NONE , setPosition , sf::Vector2f , IS_POINTER )\ 56 | X1(setRotation , METHOD , NO_RETURN , RET_NONE , setRotation , float , NO_POINTER )\ 57 | X1(setScale , METHOD , NO_RETURN , RET_NONE , setScale , sf::Vector2f , IS_POINTER )\ 58 | X1(setOrigin , METHOD , NO_RETURN , RET_NONE , setOrigin , sf::Vector2f , IS_POINTER )\ 59 | X1(move , METHOD , NO_RETURN , RET_NONE , move , sf::Vector2f , IS_POINTER )\ 60 | X1(scale , METHOD , NO_RETURN , RET_NONE , scale , sf::Vector2f , IS_POINTER )\ 61 | X1(rotate , METHOD , NO_RETURN , RET_NONE , rotate , float , NO_POINTER )\ 62 | 63 | 64 | #define __GO_FOR_IMPLEMENTATION__ 65 | #include "../../bindingHelper/macro2.hpp" 66 | 67 | FUNCTION_TO_BIND 68 | 69 | #undef __GO_FOR_IMPLEMENTATION__ 70 | #include "../../bindingHelper/macro2.hpp" 71 | 72 | luaL_Reg sfText_regs[] = 73 | { 74 | LUA_DEFAULT_CLASS_FUNC(sfText) 75 | FUNCTION_TO_BIND 76 | { NULL, NULL } 77 | }; 78 | 79 | LUA_BEGIN_REGISTER_CLASS(sfText) 80 | register_drawableType(metaTableName()); 81 | LUA_END_REGISTER_CLASS 82 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_text.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_TextEnums(lua_State * l); 5 | 6 | void register_sfText(lua_State * l); 7 | 8 | #include "../../bindingHelper/lua_template.hpp" 9 | template <> 10 | const char* metaTableName(); 11 | 12 | #include "../../bindingHelper/lua_template.hpp" 13 | template <> 14 | const char* metaTableName(); 15 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_texture.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_texture.h" 2 | 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | #include "../system/wrap_vector2u.h" 9 | 10 | #define TYPE_TO_BIND sf::Texture 11 | #define NAME_TO_BIND sfTexture 12 | 13 | IMPLEMENT_LUA_CLASS(sfTexture,sf::Texture) 14 | 15 | #define FUNCTION_TO_BIND \ 16 | X0(getMaximumSize , FUNCTION ,HAS_RETURN , RET_TYPE(unsigned int) , sf::Texture::getMaximumSize )\ 17 | X0(getSize , METHOD ,HAS_RETURN , RET_TYPE(sf::Vector2u) , getSize )\ 18 | X0(isSmooth , METHOD ,HAS_RETURN , RET_TYPE(bool) , isSmooth )\ 19 | X0(isRepeated , METHOD ,HAS_RETURN , RET_TYPE(bool) , isRepeated )\ 20 | X1(setSmooth , METHOD ,NO_RETURN , RET_NONE , setSmooth , bool , NO_POINTER )\ 21 | X1(setRepeated , METHOD ,NO_RETURN , RET_NONE , setRepeated , bool , NO_POINTER )\ 22 | X1(loadFromFile , METHOD ,HAS_RETURN , RET_TYPE(bool) , loadFromFile , std::string , NO_POINTER )\ 23 | X2(create , METHOD ,HAS_RETURN , RET_TYPE(bool) , create , unsigned int , NO_POINTER , unsigned int , NO_POINTER )\ 24 | 25 | #define __GO_FOR_IMPLEMENTATION__ 26 | #include "../../bindingHelper/macro2.hpp" 27 | 28 | FUNCTION_TO_BIND 29 | 30 | #undef __GO_FOR_IMPLEMENTATION__ 31 | #include "../../bindingHelper/macro2.hpp" 32 | 33 | luaL_Reg sfTexture_regs[] = 34 | { 35 | LUA_DEFAULT_CLASS_FUNC(sfTexture) 36 | FUNCTION_TO_BIND 37 | { NULL, NULL } 38 | }; 39 | 40 | LUA_REGISTER_CLASS(sfTexture) 41 | -------------------------------------------------------------------------------- /src/sfml/graphics/wrap_texture.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfTexture(lua_State * l); 5 | 6 | 7 | #include "../../bindingHelper/lua_template.hpp" 8 | template <> 9 | const char* metaTableName(); 10 | 11 | #include "../../bindingHelper/lua_template.hpp" 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/sfml.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "window.h" 3 | #include "system.h" 4 | #include "graphics.h" 5 | #include "audio.h" 6 | 7 | void registerSFMLModule(lua_State * l) 8 | { 9 | registerSystemModule(l); 10 | registerWindowModule(l); 11 | registerGraphicsModule(l); 12 | registerAudioModule(l); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/sfml/sfml.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void registerSFMLModule(lua_State * l); 4 | 5 | -------------------------------------------------------------------------------- /src/sfml/system.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "system/wrap_clock.h" 3 | #include "system/wrap_time.h" 4 | #include "system/wrap_vector2i.h" 5 | #include "system/wrap_vector2f.h" 6 | #include "system/wrap_vector2u.h" 7 | #include "system/wrap_vector3i.h" 8 | #include "system/wrap_vector3f.h" 9 | 10 | void registerSystemModule(lua_State * l) 11 | { 12 | register_sfClock(l); 13 | register_sfTime(l); 14 | register_sfVector2i(l); 15 | register_sfVector2u(l); 16 | register_sfVector2f(l); 17 | register_sfVector3i(l); 18 | register_sfVector3f(l); 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/sfml/system.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void registerSystemModule(lua_State * l); 4 | 5 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_clock.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_clock.h" 2 | #include 3 | 4 | #include "wrap_time.h" 5 | 6 | #include "../../bindingHelper/marco.hpp" 7 | #include "../../bindingHelper/lua_template.hpp" 8 | 9 | #define TYPE_TO_BIND sf::Clock 10 | #define NAME_TO_BIND sfClock 11 | 12 | IMPLEMENT_LUA_CLASS(sfClock,sf::Clock) 13 | 14 | #define FUNCTION_TO_BIND \ 15 | X0(restart , METHOD ,HAS_RETURN , RET_TYPE(sf::Time) , restart ) \ 16 | X0(getElapsedTime , METHOD ,HAS_RETURN , RET_TYPE(sf::Time) , getElapsedTime ) 17 | 18 | #define __GO_FOR_IMPLEMENTATION__ 19 | #include "../../bindingHelper/macro2.hpp" 20 | 21 | FUNCTION_TO_BIND 22 | 23 | #undef __GO_FOR_IMPLEMENTATION__ 24 | #include "../../bindingHelper/macro2.hpp" 25 | 26 | luaL_Reg sfClock_regs[] = 27 | { 28 | LUA_DEFAULT_CLASS_FUNC(sfClock) 29 | FUNCTION_TO_BIND 30 | { NULL, NULL } 31 | }; 32 | 33 | LUA_REGISTER_CLASS(sfClock) 34 | 35 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_clock.h: -------------------------------------------------------------------------------- 1 | #include 2 | //#include 3 | 4 | void register_sfClock(lua_State * l); 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_time.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_time.h" 2 | #include 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | template <> 9 | sf::Time* newDefault(lua_State* l) 10 | { 11 | return new sf::Time(sf::Time::Zero); 12 | } 13 | 14 | #define TYPE_TO_BIND sf::Time 15 | #define NAME_TO_BIND sfTime 16 | 17 | IMPLEMENT_LUA_CLASS(sfTime,sf::Time) 18 | //IMPLEMENT_LUA_COPY_CTOR(sfTime,sf::Time) 19 | 20 | #define FUNCTION_TO_BIND \ 21 | X0(asSeconds , METHOD ,HAS_RETURN , RET_TYPE(float) , asSeconds ) \ 22 | X0(asMilliseconds , METHOD ,HAS_RETURN , RET_TYPE(int) , asMilliseconds ) \ 23 | X0(asMicroseconds , METHOD ,HAS_RETURN , RET_TYPE(int) , asMicroseconds ) \ 24 | X1(seconds , FUNCTION ,HAS_RETURN , RET_CTOR , sf::seconds , float , NO_POINTER) \ 25 | X1(milliseconds , FUNCTION ,HAS_RETURN , RET_CTOR , sf::milliseconds , int , NO_POINTER) \ 26 | X1(microseconds , FUNCTION ,HAS_RETURN , RET_CTOR , sf::microseconds , int , NO_POINTER) \ 27 | X2(__mul , FUNCTION ,HAS_RETURN , RET_CTOR , operator* , TYPE_TO_BIND , IS_POINTER , float , NO_POINTER) \ 28 | X2(__div , FUNCTION ,HAS_RETURN , RET_CTOR , operator/ , TYPE_TO_BIND , IS_POINTER , float , NO_POINTER) \ 29 | X2(__add , FUNCTION ,HAS_RETURN , RET_CTOR , operator+ , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 30 | X2(__sub , FUNCTION ,HAS_RETURN , RET_CTOR , operator- , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 31 | X2(__eq , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator== , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 32 | X2(__lt , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator< , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 33 | X2(__le , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator<= , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 34 | 35 | #define __GO_FOR_IMPLEMENTATION__ 36 | #include "../../bindingHelper/macro2.hpp" 37 | 38 | FUNCTION_TO_BIND 39 | 40 | #undef __GO_FOR_IMPLEMENTATION__ 41 | #include "../../bindingHelper/macro2.hpp" 42 | 43 | luaL_Reg sfTime_regs[] = 44 | { 45 | LUA_DEFAULT_CLASS_FUNC(sfTime) 46 | FUNCTION_TO_BIND 47 | { NULL, NULL } 48 | }; 49 | 50 | LUA_REGISTER_CLASS(sfTime) 51 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_time.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfTime(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector2f.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_vector2f.h" 2 | #include "wrap_vector2i.h" 3 | #include "wrap_vector2u.h" 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "../../bindingHelper/marco.hpp" 10 | #include "../../bindingHelper/lua_template.hpp" 11 | 12 | 13 | template< > 14 | sf::Vector2f* lua_get(lua_State * l,int i) 15 | { 16 | if(test_type(l,i)) 17 | { 18 | sf::Vector2i* tmp = check_pointertype(l,i); 19 | copy_constructor(l,sf::Vector2f(tmp->x,tmp->y)); 20 | lua_replace(l,i); 21 | 22 | } 23 | if(test_type(l,i)) 24 | { 25 | sf::Vector2u* tmp = check_pointertype(l,i); 26 | copy_constructor(l,sf::Vector2f(tmp->x,tmp->y)); 27 | lua_replace(l,i); 28 | } 29 | if(lua_isnumber(l,i) && lua_isnumber(l,i+1)) 30 | { 31 | copy_constructor(l,sf::Vector2f(lua_get(l,i),lua_get(l,i+1))); 32 | lua_replace(l,i); 33 | lua_remove(l,i+1); 34 | } 35 | 36 | return check_pointertype(l,i); 37 | } 38 | 39 | 40 | #define TYPE_TO_BIND sf::Vector2f 41 | #define NAME_TO_BIND sfVector2f 42 | 43 | #include "../../bindingHelper/macro2.hpp" 44 | 45 | 46 | 47 | DEFAULT_CTOR_2(sf::Vector2f,float,NO_POINTER,float,NO_POINTER) 48 | 49 | 50 | IMPLEMENT_LUA_CLASS(sfVector2f,sf::Vector2f) 51 | 52 | #define FUNCTION_TO_BIND \ 53 | X2(__mul , FUNCTION ,HAS_RETURN , RET_CTOR , operator* , TYPE_TO_BIND , IS_POINTER , float , NO_POINTER) \ 54 | X2(__div , FUNCTION ,HAS_RETURN , RET_CTOR , operator/ , TYPE_TO_BIND , IS_POINTER , float , NO_POINTER) \ 55 | X2(__add , FUNCTION ,HAS_RETURN , RET_CTOR , operator+ , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 56 | X2(__sub , FUNCTION ,HAS_RETURN , RET_CTOR , operator- , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 57 | X2(__eq , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator== , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 58 | X1(setX , SETTER ,NO_RETURN , RET_NONE , x , float , NO_POINTER )\ 59 | X1(setY , SETTER ,NO_RETURN , RET_NONE , y , float , NO_POINTER )\ 60 | X0(x , GETTER ,HAS_RETURN , RET_TYPE(float) , x )\ 61 | X0(y , GETTER ,HAS_RETURN , RET_TYPE(float) , y )\ 62 | 63 | #define __GO_FOR_IMPLEMENTATION__ 64 | #include "../../bindingHelper/macro2.hpp" 65 | 66 | FUNCTION_TO_BIND 67 | 68 | #undef __GO_FOR_IMPLEMENTATION__ 69 | #include "../../bindingHelper/macro2.hpp" 70 | 71 | luaL_Reg sfVector2f_regs[] = 72 | { 73 | LUA_DEFAULT_CLASS_FUNC(sfVector2f) 74 | FUNCTION_TO_BIND 75 | { NULL, NULL } 76 | }; 77 | 78 | LUA_REGISTER_CLASS(sfVector2f) 79 | 80 | 81 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector2f.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfVector2f(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | 14 | template< > 15 | sf::Vector2f* lua_get(lua_State * l,int i); 16 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector2i.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_vector2f.h" 2 | #include "wrap_vector2i.h" 3 | #include "wrap_vector2u.h" 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "../../bindingHelper/marco.hpp" 10 | #include "../../bindingHelper/lua_template.hpp" 11 | 12 | 13 | template< > 14 | sf::Vector2i* lua_get(lua_State * l,int i) 15 | { 16 | if(test_type(l,i)) 17 | { 18 | sf::Vector2f* tmp = check_pointertype(l,i); 19 | copy_constructor(l,sf::Vector2i(tmp->x,tmp->y)); 20 | lua_replace(l,i); 21 | } 22 | if(test_type(l,i)) 23 | { 24 | sf::Vector2u* tmp = check_pointertype(l,i); 25 | copy_constructor(l,sf::Vector2i(tmp->x,tmp->y)); 26 | lua_replace(l,i); 27 | } 28 | if(lua_isnumber(l,i) && lua_isnumber(l,i+1)) 29 | { 30 | copy_constructor(l,sf::Vector2i(lua_get(l,i),lua_get(l,i+1))); 31 | lua_replace(l,i); 32 | lua_remove(l,i+1); 33 | } 34 | return check_pointertype(l,i); 35 | } 36 | 37 | 38 | #define TYPE_TO_BIND sf::Vector2i 39 | #define NAME_TO_BIND sfVector2i 40 | 41 | 42 | #include "../../bindingHelper/macro2.hpp" 43 | 44 | 45 | DEFAULT_CTOR_2(sf::Vector2i,int,NO_POINTER,int,NO_POINTER) 46 | 47 | IMPLEMENT_LUA_CLASS(sfVector2i,sf::Vector2i) 48 | 49 | #define FUNCTION_TO_BIND \ 50 | X2(__mul , FUNCTION ,HAS_RETURN , RET_CTOR , operator* , TYPE_TO_BIND , IS_POINTER , int , NO_POINTER) \ 51 | X2(__div , FUNCTION ,HAS_RETURN , RET_CTOR , operator/ , TYPE_TO_BIND , IS_POINTER , int , NO_POINTER) \ 52 | X2(__add , FUNCTION ,HAS_RETURN , RET_CTOR , operator+ , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 53 | X2(__sub , FUNCTION ,HAS_RETURN , RET_CTOR , operator- , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 54 | X2(__eq , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator== , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 55 | X1(setX , SETTER ,NO_RETURN , RET_NONE , x , int , NO_POINTER )\ 56 | X1(setY , SETTER ,NO_RETURN , RET_NONE , y , int , NO_POINTER )\ 57 | X0(x , GETTER ,HAS_RETURN , RET_TYPE(int) , x )\ 58 | X0(y , GETTER ,HAS_RETURN , RET_TYPE(int) , y )\ 59 | 60 | #define __GO_FOR_IMPLEMENTATION__ 61 | #include "../../bindingHelper/macro2.hpp" 62 | 63 | FUNCTION_TO_BIND 64 | 65 | #undef __GO_FOR_IMPLEMENTATION__ 66 | #include "../../bindingHelper/macro2.hpp" 67 | 68 | luaL_Reg sfVector2i_regs[] = 69 | { 70 | LUA_DEFAULT_CLASS_FUNC(sfVector2i) 71 | FUNCTION_TO_BIND 72 | { NULL, NULL } 73 | }; 74 | 75 | LUA_REGISTER_CLASS(sfVector2i) 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector2i.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfVector2i(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | 14 | template< > 15 | sf::Vector2i* lua_get(lua_State * l,int i); 16 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector2u.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_vector2u.h" 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "../../bindingHelper/marco.hpp" 8 | #include "../../bindingHelper/lua_template.hpp" 9 | #include "../system/wrap_vector2i.h" 10 | #include "../system/wrap_vector2f.h" 11 | 12 | 13 | #define TYPE_TO_BIND sf::Vector2u 14 | #define NAME_TO_BIND sfVector2u 15 | 16 | template< > 17 | sf::Vector2u* lua_get(lua_State * l,int i) 18 | { 19 | 20 | if(test_type(l,i)) 21 | { 22 | sf::Vector2i* tmp = check_pointertype(l,i); 23 | copy_constructor(l,sf::Vector2u(tmp->x,tmp->y)); 24 | lua_replace(l,i); 25 | } 26 | if(test_type(l,i)) 27 | { 28 | sf::Vector2f* tmp = check_pointertype(l,i); 29 | copy_constructor(l,sf::Vector2u(tmp->x,tmp->y)); 30 | lua_replace(l,i); 31 | } 32 | if(lua_isnumber(l,i) && lua_isnumber(l,i+1)) 33 | { 34 | copy_constructor(l,sf::Vector2u(lua_get(l,i),lua_get(l,i+1))); 35 | lua_replace(l,i); 36 | lua_remove(l,i+1); 37 | } 38 | return check_pointertype(l,i); 39 | } 40 | 41 | 42 | #include "../../bindingHelper/macro2.hpp" 43 | 44 | 45 | DEFAULT_CTOR_2(sf::Vector2u,unsigned int,NO_POINTER,unsigned int,NO_POINTER) 46 | 47 | IMPLEMENT_LUA_CLASS(sfVector2u,sf::Vector2u) 48 | 49 | #define FUNCTION_TO_BIND \ 50 | X2(__mul , FUNCTION ,HAS_RETURN , RET_CTOR , operator* , TYPE_TO_BIND , IS_POINTER , unsigned int , NO_POINTER) \ 51 | X2(__div , FUNCTION ,HAS_RETURN , RET_CTOR , operator/ , TYPE_TO_BIND , IS_POINTER , unsigned int , NO_POINTER) \ 52 | X2(__add , FUNCTION ,HAS_RETURN , RET_CTOR , operator+ , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 53 | X2(__sub , FUNCTION ,HAS_RETURN , RET_CTOR , operator- , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 54 | X2(__eq , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator== , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 55 | X1(setX , SETTER ,NO_RETURN , RET_NONE , x , unsigned int , NO_POINTER )\ 56 | X1(setY , SETTER ,NO_RETURN , RET_NONE , y , unsigned int , NO_POINTER )\ 57 | X0(x , GETTER ,HAS_RETURN , RET_TYPE(unsigned int) , x )\ 58 | X0(y , GETTER ,HAS_RETURN , RET_TYPE(unsigned int) , y )\ 59 | 60 | #define __GO_FOR_IMPLEMENTATION__ 61 | #include "../../bindingHelper/macro2.hpp" 62 | 63 | FUNCTION_TO_BIND 64 | 65 | #undef __GO_FOR_IMPLEMENTATION__ 66 | #include "../../bindingHelper/macro2.hpp" 67 | 68 | luaL_Reg sfVector2u_regs[] = 69 | { 70 | LUA_DEFAULT_CLASS_FUNC(sfVector2u) 71 | FUNCTION_TO_BIND 72 | { NULL, NULL } 73 | }; 74 | 75 | LUA_REGISTER_CLASS(sfVector2u) 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector2u.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfVector2u(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | 14 | template< > 15 | sf::Vector2u* lua_get(lua_State * l,int i); 16 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector3f.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_vector2f.h" 2 | #include "wrap_vector2i.h" 3 | #include "wrap_vector2u.h" 4 | #include 5 | #include 6 | 7 | #include "../../bindingHelper/marco.hpp" 8 | #include "../../bindingHelper/lua_template.hpp" 9 | 10 | 11 | #define TYPE_TO_BIND sf::Vector3f 12 | #define NAME_TO_BIND sfVector3f 13 | 14 | 15 | #include "../../bindingHelper/macro2.hpp" 16 | 17 | 18 | DEFAULT_CTOR_3(sf::Vector3f,float,NO_POINTER,float,NO_POINTER,float,NO_POINTER) 19 | 20 | IMPLEMENT_LUA_CLASS(sfVector3f,sf::Vector3f) 21 | 22 | #define FUNCTION_TO_BIND \ 23 | X2(__mul , FUNCTION ,HAS_RETURN , RET_CTOR , operator* , TYPE_TO_BIND , IS_POINTER , float , NO_POINTER) \ 24 | X2(__div , FUNCTION ,HAS_RETURN , RET_CTOR , operator/ , TYPE_TO_BIND , IS_POINTER , float , NO_POINTER) \ 25 | X2(__add , FUNCTION ,HAS_RETURN , RET_CTOR , operator+ , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 26 | X2(__sub , FUNCTION ,HAS_RETURN , RET_CTOR , operator- , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 27 | X2(__eq , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator== , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 28 | X1(setX , SETTER ,NO_RETURN , RET_NONE , x , float , NO_POINTER )\ 29 | X1(setY , SETTER ,NO_RETURN , RET_NONE , y , float , NO_POINTER )\ 30 | X1(setZ , SETTER ,NO_RETURN , RET_NONE , z , float , NO_POINTER )\ 31 | X0(z , GETTER ,HAS_RETURN , RET_TYPE(float) , z )\ 32 | X0(x , GETTER ,HAS_RETURN , RET_TYPE(float) , x )\ 33 | X0(y , GETTER ,HAS_RETURN , RET_TYPE(float) , y )\ 34 | 35 | 36 | #define __GO_FOR_IMPLEMENTATION__ 37 | #include "../../bindingHelper/macro2.hpp" 38 | 39 | FUNCTION_TO_BIND 40 | 41 | #undef __GO_FOR_IMPLEMENTATION__ 42 | #include "../../bindingHelper/macro2.hpp" 43 | 44 | luaL_Reg sfVector3f_regs[] = 45 | { 46 | LUA_DEFAULT_CLASS_FUNC(sfVector3f) 47 | FUNCTION_TO_BIND 48 | { NULL, NULL } 49 | }; 50 | 51 | LUA_REGISTER_CLASS(sfVector3f) 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector3f.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfVector3f(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector3i.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_vector3i.h" 2 | #include 3 | #include 4 | 5 | #include "../../bindingHelper/marco.hpp" 6 | #include "../../bindingHelper/lua_template.hpp" 7 | 8 | 9 | #define TYPE_TO_BIND sf::Vector3i 10 | #define NAME_TO_BIND sfVector3i 11 | 12 | 13 | #include "../../bindingHelper/macro2.hpp" 14 | 15 | 16 | DEFAULT_CTOR_3(sf::Vector3i,int,NO_POINTER,int,NO_POINTER,int,NO_POINTER) 17 | 18 | IMPLEMENT_LUA_CLASS(sfVector3i,sf::Vector3i) 19 | 20 | #define FUNCTION_TO_BIND \ 21 | X2(__mul , FUNCTION ,HAS_RETURN , RET_CTOR , operator* , TYPE_TO_BIND , IS_POINTER , int , NO_POINTER) \ 22 | X2(__div , FUNCTION ,HAS_RETURN , RET_CTOR , operator/ , TYPE_TO_BIND , IS_POINTER , int , NO_POINTER) \ 23 | X2(__add , FUNCTION ,HAS_RETURN , RET_CTOR , operator+ , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 24 | X2(__sub , FUNCTION ,HAS_RETURN , RET_CTOR , operator- , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 25 | X2(__eq , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , operator== , TYPE_TO_BIND , IS_POINTER , TYPE_TO_BIND , IS_POINTER) \ 26 | X1(setX , SETTER ,NO_RETURN , RET_NONE , x , int , NO_POINTER )\ 27 | X1(setY , SETTER ,NO_RETURN , RET_NONE , y , int , NO_POINTER )\ 28 | X1(setZ , SETTER ,NO_RETURN , RET_NONE , z , int , NO_POINTER )\ 29 | X0(z , GETTER ,HAS_RETURN , RET_TYPE(int) , z )\ 30 | X0(x , GETTER ,HAS_RETURN , RET_TYPE(int) , x )\ 31 | X0(y , GETTER ,HAS_RETURN , RET_TYPE(int) , y )\ 32 | 33 | 34 | #define __GO_FOR_IMPLEMENTATION__ 35 | #include "../../bindingHelper/macro2.hpp" 36 | 37 | FUNCTION_TO_BIND 38 | 39 | #undef __GO_FOR_IMPLEMENTATION__ 40 | #include "../../bindingHelper/macro2.hpp" 41 | 42 | luaL_Reg sfVector3i_regs[] = 43 | { 44 | LUA_DEFAULT_CLASS_FUNC(sfVector3i) 45 | FUNCTION_TO_BIND 46 | { NULL, NULL } 47 | }; 48 | 49 | LUA_REGISTER_CLASS(sfVector3i) 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/sfml/system/wrap_vector3i.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_sfVector3i(lua_State * l); 5 | 6 | #include "../../bindingHelper/lua_template.hpp" 7 | template <> 8 | const char* metaTableName(); 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | -------------------------------------------------------------------------------- /src/sfml/window.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "window/wrap_window.h" 3 | #include "window/wrap_videomode.h" 4 | #include "window/wrap_event.h" 5 | #include "window/wrap_mouse.h" 6 | #include "window/wrap_keyboard.h" 7 | #include "window/event/wrap_mouse_button_event.h" 8 | #include "window/event/wrap_mouse_move_event.h" 9 | #include "window/event/wrap_mouse_wheel_event.h" 10 | #include "window/event/wrap_size_event.h" 11 | #include "window/event/wrap_key_event.h" 12 | 13 | 14 | void registerWindowModule(lua_State * l) 15 | { 16 | register_EventEnums(l); 17 | register_KeyBoardEnums(l); 18 | register_MouseEnums(l); 19 | register_WindowEnums(l); 20 | 21 | register_sfWindow(l); 22 | register_sfVideoMode(l); 23 | register_sfKeyboard(l); 24 | register_sfMouse(l); 25 | register_sfEvent(l); 26 | register_sfMouseButtonEvent(l); 27 | register_sfMouseMoveEvent(l); 28 | register_sfMouseWheelEvent(l); 29 | register_sfSizeEvent(l); 30 | register_sfKeyEvent(l); 31 | 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/sfml/window.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void registerWindowModule(lua_State * l); 4 | 5 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_key_event.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_key_event.h" 2 | #include 3 | 4 | #include "../wrap_keyboard.h" 5 | 6 | #include 7 | 8 | #include "../../../bindingHelper/marco.hpp" 9 | #include "../../../bindingHelper/lua_template.hpp" 10 | 11 | 12 | #define TYPE_TO_BIND sf::Event::KeyEvent 13 | #define NAME_TO_BIND sfKeyEvent 14 | 15 | IMPLEMENT_LUA_CLASS(sfKeyEvent,sf::Event::KeyEvent) 16 | 17 | #define FUNCTION_TO_BIND \ 18 | X0(code , GETTER ,HAS_RETURN , RET_TYPE( int) , code )\ 19 | X0(alt , GETTER ,HAS_RETURN , RET_TYPE( bool) , alt )\ 20 | X0(control , GETTER ,HAS_RETURN , RET_TYPE( bool) , control )\ 21 | X0(shift , GETTER ,HAS_RETURN , RET_TYPE( bool) , shift )\ 22 | X0(system , GETTER ,HAS_RETURN , RET_TYPE( bool) , system )\ 23 | 24 | #define __GO_FOR_IMPLEMENTATION__ 25 | #include "../../../bindingHelper/macro2.hpp" 26 | 27 | FUNCTION_TO_BIND 28 | 29 | #undef __GO_FOR_IMPLEMENTATION__ 30 | #include "../../../bindingHelper/macro2.hpp" 31 | 32 | luaL_Reg sfKeyEvent_regs[] = 33 | { 34 | LUA_DEFAULT_CLASS_FUNC(sfKeyEvent) 35 | FUNCTION_TO_BIND 36 | { NULL, NULL } 37 | }; 38 | 39 | LUA_REGISTER_CLASS(sfKeyEvent) 40 | 41 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_key_event.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void register_sfKeyEvent(lua_State * l); 6 | 7 | 8 | #include "../../../bindingHelper/lua_template.hpp" 9 | template <> 10 | const char* metaTableName(); 11 | 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_mouse_button_event.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_mouse_button_event.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "../../../bindingHelper/marco.hpp" 7 | #include "../../../bindingHelper/lua_template.hpp" 8 | 9 | #include "../wrap_mouse.h" 10 | 11 | #define TYPE_TO_BIND sf::Event::MouseButtonEvent 12 | #define NAME_TO_BIND sfMouseButtonEvent 13 | 14 | IMPLEMENT_LUA_CLASS(sfMouseButtonEvent,sf::Event::MouseButtonEvent) 15 | 16 | #define FUNCTION_TO_BIND \ 17 | X0(button , GETTER ,HAS_RETURN , RET_TYPE( int) , button )\ 18 | X0(x , GETTER ,HAS_RETURN , RET_TYPE( int) , x )\ 19 | X0(y , GETTER ,HAS_RETURN , RET_TYPE( int) , y )\ 20 | 21 | #define __GO_FOR_IMPLEMENTATION__ 22 | #include "../../../bindingHelper/macro2.hpp" 23 | 24 | FUNCTION_TO_BIND 25 | 26 | #undef __GO_FOR_IMPLEMENTATION__ 27 | #include "../../../bindingHelper/macro2.hpp" 28 | 29 | luaL_Reg sfMouseButtonEvent_regs[] = 30 | { 31 | LUA_DEFAULT_CLASS_FUNC(sfMouseButtonEvent) 32 | FUNCTION_TO_BIND 33 | { NULL, NULL } 34 | }; 35 | 36 | LUA_REGISTER_CLASS(sfMouseButtonEvent) 37 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_mouse_button_event.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void register_sfMouseButtonEvent(lua_State * l); 6 | 7 | 8 | #include "../../../bindingHelper/lua_template.hpp" 9 | template <> 10 | const char* metaTableName(); 11 | 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_mouse_move_event.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_mouse_move_event.h" 2 | #include 3 | #include 4 | 5 | #include "../../../bindingHelper/marco.hpp" 6 | #include "../../../bindingHelper/lua_template.hpp" 7 | 8 | 9 | #define TYPE_TO_BIND sf::Event::MouseMoveEvent 10 | #define NAME_TO_BIND sfMouseMoveEvent 11 | 12 | IMPLEMENT_LUA_CLASS(sfMouseMoveEvent,sf::Event::MouseMoveEvent) 13 | 14 | #define FUNCTION_TO_BIND \ 15 | X0(x , GETTER ,HAS_RETURN , RET_TYPE(int) , x )\ 16 | X0(y , GETTER ,HAS_RETURN , RET_TYPE(int) , y )\ 17 | 18 | 19 | #define __GO_FOR_IMPLEMENTATION__ 20 | #include "../../../bindingHelper/macro2.hpp" 21 | 22 | FUNCTION_TO_BIND 23 | 24 | #undef __GO_FOR_IMPLEMENTATION__ 25 | #include "../../../bindingHelper/macro2.hpp" 26 | 27 | luaL_Reg sfMouseMoveEvent_regs[] = 28 | { 29 | LUA_DEFAULT_CLASS_FUNC(sfMouseMoveEvent) 30 | FUNCTION_TO_BIND 31 | { NULL, NULL } 32 | }; 33 | 34 | LUA_REGISTER_CLASS(sfMouseMoveEvent) 35 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_mouse_move_event.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void register_sfMouseMoveEvent(lua_State * l); 6 | 7 | 8 | #include "../../../bindingHelper/lua_template.hpp" 9 | template <> 10 | const char* metaTableName(); 11 | 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_mouse_wheel_event.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_mouse_wheel_event.h" 2 | 3 | #include 4 | 5 | #include "../../../bindingHelper/marco.hpp" 6 | #include "../../../bindingHelper/lua_template.hpp" 7 | 8 | 9 | #define TYPE_TO_BIND sf::Event::MouseWheelEvent 10 | #define NAME_TO_BIND sfMouseWheelEvent 11 | 12 | IMPLEMENT_LUA_CLASS(sfMouseWheelEvent,sf::Event::MouseWheelEvent) 13 | 14 | #define FUNCTION_TO_BIND \ 15 | X0(x , GETTER ,HAS_RETURN , RET_TYPE(int) , x )\ 16 | X0(y , GETTER ,HAS_RETURN , RET_TYPE(int) , y )\ 17 | X0(delta , GETTER ,HAS_RETURN , RET_TYPE(int) , delta )\ 18 | 19 | #define __GO_FOR_IMPLEMENTATION__ 20 | #include "../../../bindingHelper/macro2.hpp" 21 | 22 | FUNCTION_TO_BIND 23 | 24 | #undef __GO_FOR_IMPLEMENTATION__ 25 | #include "../../../bindingHelper/macro2.hpp" 26 | 27 | luaL_Reg sfMouseWheelEvent_regs[] = 28 | { 29 | LUA_DEFAULT_CLASS_FUNC(sfMouseWheelEvent) 30 | FUNCTION_TO_BIND 31 | { NULL, NULL } 32 | }; 33 | 34 | LUA_REGISTER_CLASS(sfMouseWheelEvent) 35 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_mouse_wheel_event.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void register_sfMouseWheelEvent(lua_State * l); 6 | 7 | 8 | #include "../../../bindingHelper/lua_template.hpp" 9 | template <> 10 | const char* metaTableName(); 11 | 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_size_event.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_size_event.h" 2 | #include 3 | 4 | #include 5 | 6 | #include "../../../bindingHelper/marco.hpp" 7 | #include "../../../bindingHelper/lua_template.hpp" 8 | 9 | 10 | #define TYPE_TO_BIND sf::Event::SizeEvent 11 | #define NAME_TO_BIND sfSizeEvent 12 | 13 | IMPLEMENT_LUA_CLASS(sfSizeEvent,sf::Event::SizeEvent) 14 | 15 | #define FUNCTION_TO_BIND \ 16 | X0(width , GETTER ,HAS_RETURN , RET_TYPE(unsigned int) , width )\ 17 | X0(height , GETTER ,HAS_RETURN , RET_TYPE(unsigned int) , height )\ 18 | 19 | #define __GO_FOR_IMPLEMENTATION__ 20 | #include "../../../bindingHelper/macro2.hpp" 21 | 22 | FUNCTION_TO_BIND 23 | 24 | #undef __GO_FOR_IMPLEMENTATION__ 25 | #include "../../../bindingHelper/macro2.hpp" 26 | 27 | luaL_Reg sfSizeEvent_regs[] = 28 | { 29 | LUA_DEFAULT_CLASS_FUNC(sfSizeEvent) 30 | FUNCTION_TO_BIND 31 | { NULL, NULL } 32 | }; 33 | 34 | LUA_REGISTER_CLASS(sfSizeEvent) 35 | 36 | -------------------------------------------------------------------------------- /src/sfml/window/event/wrap_size_event.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void register_sfSizeEvent(lua_State * l); 6 | 7 | 8 | #include "../../../bindingHelper/lua_template.hpp" 9 | template <> 10 | const char* metaTableName(); 11 | 12 | template <> 13 | const char* metaTableName(); 14 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_event.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_event.h" 2 | #include 3 | #include "../../bindingHelper/enum.hpp" 4 | 5 | 6 | #include "../window/event/wrap_key_event.h" 7 | #include "../window/event/wrap_mouse_button_event.h" 8 | #include "../window/event/wrap_mouse_move_event.h" 9 | #include "../window/event/wrap_mouse_wheel_event.h" 10 | #include "../window/event/wrap_size_event.h" 11 | 12 | void register_EventEnums(lua_State * l) 13 | { 14 | add_enum_to_lua(l,"sfEventType", 15 | "Closed" , sf::Event::Closed, 16 | "Resized" , sf::Event::Resized, 17 | "LostFocus" , sf::Event::LostFocus, 18 | "GainedFocus" , sf::Event::GainedFocus, 19 | "TextEntered" , sf::Event::TextEntered, 20 | "KeyPressed" , sf::Event::KeyPressed, 21 | "KeyReleased" , sf::Event::KeyReleased, 22 | "MouseWheelMoved" , sf::Event::MouseWheelMoved, 23 | "MouseButtonPressed" , sf::Event::MouseButtonPressed, 24 | "MouseButtonReleased" , sf::Event::MouseButtonReleased, 25 | "MouseMoved" , sf::Event::MouseMoved, 26 | "MouseLeft" , sf::Event::MouseLeft, 27 | "JoystickButtonPressed" , sf::Event::JoystickButtonPressed, 28 | "JoystickButtonReleased" , sf::Event::JoystickButtonReleased, 29 | "JoystickMoved" , sf::Event::JoystickMoved, 30 | "JoystickConnected" , sf::Event::JoystickConnected, 31 | "JoystickDisconnected" , sf::Event::JoystickDisconnected, 32 | "Count" , sf::Event::Count, 33 | nullptr); 34 | 35 | } 36 | 37 | #include 38 | 39 | #include "../../bindingHelper/marco.hpp" 40 | #include "../../bindingHelper/lua_template.hpp" 41 | 42 | 43 | #define TYPE_TO_BIND sf::Event 44 | #define NAME_TO_BIND sfEvent 45 | 46 | IMPLEMENT_LUA_CLASS(sfEvent,sf::Event) 47 | 48 | #define FUNCTION_TO_BIND \ 49 | X0(type , GETTER ,HAS_RETURN , RET_TYPE( int) , type )\ 50 | X0(size , GETTER ,HAS_RETURN , RET_TYPE( sf::Event::SizeEvent ) , size )\ 51 | X0(key , GETTER ,HAS_RETURN , RET_TYPE( sf::Event::KeyEvent ) , key )\ 52 | X0(mouseMove , GETTER ,HAS_RETURN , RET_TYPE( sf::Event::MouseMoveEvent ) , mouseMove )\ 53 | X0(mouseButton , GETTER ,HAS_RETURN , RET_TYPE( sf::Event::MouseButtonEvent) , mouseButton )\ 54 | X0(mouseWheel , GETTER ,HAS_RETURN , RET_TYPE( sf::Event::MouseWheelEvent ) , mouseWheel )\ 55 | 56 | #define __GO_FOR_IMPLEMENTATION__ 57 | #include "../../bindingHelper/macro2.hpp" 58 | 59 | FUNCTION_TO_BIND 60 | 61 | #undef __GO_FOR_IMPLEMENTATION__ 62 | #include "../../bindingHelper/macro2.hpp" 63 | 64 | luaL_Reg sfEvent_regs[] = 65 | { 66 | LUA_DEFAULT_CLASS_FUNC(sfEvent) 67 | FUNCTION_TO_BIND 68 | { NULL, NULL } 69 | }; 70 | 71 | LUA_REGISTER_CLASS(sfEvent) 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_event.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_EventEnums(lua_State * l); 5 | 6 | 7 | void register_sfEvent(lua_State * l); 8 | 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | 14 | #include "../../bindingHelper/lua_template.hpp" 15 | template <> 16 | const char* metaTableName(); 17 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_keyboard.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_keyboard.h" 2 | #include 3 | 4 | #include 5 | 6 | #include "../../bindingHelper/marco.hpp" 7 | #include "../../bindingHelper/lua_template.hpp" 8 | #include "../../bindingHelper/enum.hpp" 9 | 10 | void register_KeyBoardEnums(lua_State * l) 11 | { 12 | add_enum_to_lua(l,"sfKey", 13 | "A" , sf::Keyboard::A , 14 | "B" , sf::Keyboard::B , 15 | "C" , sf::Keyboard::C , 16 | "D" , sf::Keyboard::D , 17 | "E" , sf::Keyboard::E , 18 | "F" , sf::Keyboard::F , 19 | "G" , sf::Keyboard::G , 20 | "H" , sf::Keyboard::H , 21 | "I" , sf::Keyboard::I , 22 | "J" , sf::Keyboard::J , 23 | "K" , sf::Keyboard::K , 24 | "L" , sf::Keyboard::L , 25 | "M" , sf::Keyboard::M , 26 | "N" , sf::Keyboard::N , 27 | "O" , sf::Keyboard::O , 28 | "P" , sf::Keyboard::P , 29 | "Q" , sf::Keyboard::Q , 30 | "R" , sf::Keyboard::R , 31 | "S" , sf::Keyboard::S , 32 | "T" , sf::Keyboard::T , 33 | "U" , sf::Keyboard::U , 34 | "V" , sf::Keyboard::V , 35 | "W" , sf::Keyboard::W , 36 | "X" , sf::Keyboard::X , 37 | "Y" , sf::Keyboard::Y , 38 | "Z" , sf::Keyboard::Z , 39 | "Num0" , sf::Keyboard::Num0 , 40 | "Num1" , sf::Keyboard::Num1 , 41 | "Num2" , sf::Keyboard::Num2 , 42 | "Num3" , sf::Keyboard::Num3 , 43 | "Num4" , sf::Keyboard::Num4 , 44 | "Num5" , sf::Keyboard::Num5 , 45 | "Num6" , sf::Keyboard::Num6 , 46 | "Num7" , sf::Keyboard::Num7 , 47 | "Num8" , sf::Keyboard::Num8 , 48 | "Num9" , sf::Keyboard::Num9 , 49 | "Escape" , sf::Keyboard::Escape , 50 | "LControl" , sf::Keyboard::LControl , 51 | "LShift" , sf::Keyboard::LShift , 52 | "LAlt" , sf::Keyboard::LAlt , 53 | "LSystem" , sf::Keyboard::LSystem , 54 | "RControl" , sf::Keyboard::RControl , 55 | "RShift" , sf::Keyboard::RShift , 56 | "RAlt" , sf::Keyboard::RAlt , 57 | "RSystem" , sf::Keyboard::RSystem , 58 | "Menu" , sf::Keyboard::Menu , 59 | "LBracket" , sf::Keyboard::LBracket , 60 | "RBracket" , sf::Keyboard::RBracket , 61 | "SemiColon" , sf::Keyboard::SemiColon , 62 | "Comma" , sf::Keyboard::Comma , 63 | "Period" , sf::Keyboard::Period , 64 | "Quote" , sf::Keyboard::Quote , 65 | "Slash" , sf::Keyboard::Slash , 66 | "BackSlash" , sf::Keyboard::BackSlash , 67 | "Tilde" , sf::Keyboard::Tilde , 68 | "Equal" , sf::Keyboard::Equal , 69 | "Dash" , sf::Keyboard::Dash , 70 | "Space" , sf::Keyboard::Space , 71 | "Return" , sf::Keyboard::Return , 72 | "BackSpace" , sf::Keyboard::BackSpace , 73 | "Tab" , sf::Keyboard::Tab , 74 | "PageUp" , sf::Keyboard::PageUp , 75 | "PageDown" , sf::Keyboard::PageDown , 76 | "End" , sf::Keyboard::End , 77 | "Home" , sf::Keyboard::Home , 78 | "Insert" , sf::Keyboard::Insert , 79 | "Delete" , sf::Keyboard::Delete , 80 | "Add" , sf::Keyboard::Add , 81 | "Subtract" , sf::Keyboard::Subtract , 82 | "Multiply" , sf::Keyboard::Multiply , 83 | "Divide" , sf::Keyboard::Divide , 84 | "Left" , sf::Keyboard::Left , 85 | "Right" , sf::Keyboard::Right , 86 | "Up" , sf::Keyboard::Up , 87 | "Down" , sf::Keyboard::Down , 88 | "Numpad0" , sf::Keyboard::Numpad0 , 89 | "Numpad1" , sf::Keyboard::Numpad1 , 90 | "Numpad2" , sf::Keyboard::Numpad2 , 91 | "Numpad3" , sf::Keyboard::Numpad3 , 92 | "Numpad4" , sf::Keyboard::Numpad4 , 93 | "Numpad5" , sf::Keyboard::Numpad5 , 94 | "Numpad6" , sf::Keyboard::Numpad6 , 95 | "Numpad7" , sf::Keyboard::Numpad7 , 96 | "Numpad8" , sf::Keyboard::Numpad8 , 97 | "Numpad9" , sf::Keyboard::Numpad9 , 98 | "F1" , sf::Keyboard::F1 , 99 | "F2" , sf::Keyboard::F2 , 100 | "F3" , sf::Keyboard::F3 , 101 | "F4" , sf::Keyboard::F4 , 102 | "F5" , sf::Keyboard::F5 , 103 | "F6" , sf::Keyboard::F6 , 104 | "F7" , sf::Keyboard::F7 , 105 | "F8" , sf::Keyboard::F8 , 106 | "F9" , sf::Keyboard::F9 , 107 | "F10" , sf::Keyboard::F10 , 108 | "F11" , sf::Keyboard::F11 , 109 | "F12" , sf::Keyboard::F12 , 110 | "F13" , sf::Keyboard::F13 , 111 | "F14" , sf::Keyboard::F14 , 112 | "F15" , sf::Keyboard::F15 , 113 | "Pause" , sf::Keyboard::Pause , 114 | "KeyCount" , sf::Keyboard::KeyCount , 115 | nullptr); 116 | 117 | } 118 | 119 | template<> 120 | sf::Keyboard::Key lua_get(lua_State * l,int i) 121 | { 122 | unsigned int value = lua_get(l,i); 123 | if(value >= sf::Keyboard::KeyCount) luaL_argerror(l,i,"Not valid enum value"); 124 | return (sf::Keyboard::Key)value; 125 | } 126 | 127 | 128 | 129 | #define TYPE_TO_BIND sf::Keyboard 130 | #define NAME_TO_BIND sfKeyboard 131 | 132 | IMPLEMENT_LUA_CLASS(sfKeyboard,sf::Keyboard) 133 | 134 | #define FUNCTION_TO_BIND \ 135 | X1(isKeyPressed , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , sf::Keyboard::isKeyPressed ,sf::Keyboard::Key,NO_POINTER )\ 136 | 137 | #define __GO_FOR_IMPLEMENTATION__ 138 | #include "../../bindingHelper/macro2.hpp" 139 | 140 | FUNCTION_TO_BIND 141 | 142 | #undef __GO_FOR_IMPLEMENTATION__ 143 | #include "../../bindingHelper/macro2.hpp" 144 | 145 | luaL_Reg sfKeyboard_regs[] = 146 | { 147 | LUA_DEFAULT_CLASS_FUNC(sfKeyboard) 148 | FUNCTION_TO_BIND 149 | { NULL, NULL } 150 | }; 151 | 152 | LUA_REGISTER_CLASS(sfKeyboard) 153 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_keyboard.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_KeyBoardEnums(lua_State * l); 5 | 6 | 7 | void register_sfKeyboard(lua_State * l); 8 | 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | 14 | template <> 15 | const char* metaTableName(); 16 | 17 | template<> 18 | sf::Keyboard::Key lua_get(lua_State * l,int i); 19 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_mouse.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_mouse.h" 2 | #include 3 | #include "../../bindingHelper/enum.hpp" 4 | 5 | 6 | #include "../system/wrap_vector2i.h" 7 | #include "../system/wrap_vector2u.h" 8 | #include "../graphics/wrap_render_window.h" 9 | 10 | 11 | void register_MouseEnums(lua_State * l) 12 | { 13 | add_enum_to_lua(l,"sfMouseButton", 14 | "Left" , sf::Mouse::Left, 15 | "Right" , sf::Mouse::Right, 16 | "Middle" , sf::Mouse::Middle, 17 | "XButton1" , sf::Mouse::XButton1, 18 | "XButton2" , sf::Mouse::XButton2, 19 | "ButtonCount" , sf::Mouse::ButtonCount, 20 | nullptr); 21 | 22 | } 23 | 24 | template<> 25 | sf::Mouse::Button lua_get(lua_State * l,int i) 26 | { 27 | unsigned int value = lua_get(l,i); 28 | if(value >= sf::Mouse::ButtonCount) luaL_argerror(l,i,"Not valid enum value"); 29 | return (sf::Mouse::Button)value; 30 | } 31 | 32 | #include 33 | 34 | #include "../../bindingHelper/marco.hpp" 35 | #include "../../bindingHelper/lua_template.hpp" 36 | 37 | 38 | #define TYPE_TO_BIND sf::Mouse 39 | #define NAME_TO_BIND sfMouse 40 | 41 | IMPLEMENT_LUA_CLASS(sfMouse,sf::Mouse) 42 | 43 | #define FUNCTION_TO_BIND \ 44 | X1(isButtonPressed , FUNCTION ,HAS_RETURN , RET_TYPE(bool) , sf::Mouse::isButtonPressed , sf::Mouse::Button , NO_POINTER) \ 45 | X0(getPosition , FUNCTION ,HAS_RETURN , RET_TYPE(sf::Vector2i) , sf::Mouse::getPosition) \ 46 | X1(setPosition , FUNCTION ,NO_RETURN , RET_NONE , sf::Mouse::setPosition , sf::Vector2i , IS_POINTER) \ 47 | X1(getPositionRelativeto , FUNCTION ,HAS_RETURN , RET_TYPE(sf::Vector2i) , sf::Mouse::getPosition , sf::RenderWindow,IS_POINTER) \ 48 | X2(setPositionRelativeto , FUNCTION ,NO_RETURN , RET_NONE , sf::Mouse::setPosition , sf::Vector2i , IS_POINTER, sf::RenderWindow,IS_POINTER) \ 49 | 50 | 51 | #define __GO_FOR_IMPLEMENTATION__ 52 | #include "../../bindingHelper/macro2.hpp" 53 | 54 | FUNCTION_TO_BIND 55 | 56 | #undef __GO_FOR_IMPLEMENTATION__ 57 | #include "../../bindingHelper/macro2.hpp" 58 | 59 | luaL_Reg sfMouse_regs[] = 60 | { 61 | LUA_DEFAULT_CLASS_FUNC(sfMouse) 62 | FUNCTION_TO_BIND 63 | { NULL, NULL } 64 | }; 65 | 66 | LUA_REGISTER_CLASS(sfMouse) 67 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_mouse.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void register_MouseEnums(lua_State * l); 5 | 6 | 7 | void register_sfMouse(lua_State * l); 8 | 9 | 10 | #include "../../bindingHelper/lua_template.hpp" 11 | template <> 12 | const char* metaTableName(); 13 | 14 | template <> 15 | const char* metaTableName(); 16 | 17 | template<> 18 | sf::Mouse::Button lua_get(lua_State * l,int i); 19 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_videomode.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_videomode.h" 2 | 3 | #include 4 | 5 | #define TYPE_TO_BIND sf::VideoMode 6 | #define NAME_TO_BIND sfVideoMode 7 | 8 | 9 | 10 | #include "../../bindingHelper/marco.hpp" 11 | #include "../../bindingHelper/macro2.hpp" 12 | #include "../../bindingHelper/lua_template.hpp" 13 | 14 | 15 | DEFAULT_CTOR_3(sf::VideoMode,unsigned int,NO_POINTER,unsigned int,NO_POINTER,unsigned int,NO_POINTER) 16 | 17 | IMPLEMENT_LUA_CLASS(sfVideoMode,sf::VideoMode) 18 | 19 | #define FUNCTION_TO_BIND \ 20 | X0(isValid , METHOD ,HAS_RETURN , RET_TYPE( bool) , isValid ) \ 21 | X0(width , GETTER ,HAS_RETURN , RET_TYPE(unsigned int) , width )\ 22 | X0(height , GETTER ,HAS_RETURN , RET_TYPE(unsigned int) , height )\ 23 | X0(bitsPerPixel , GETTER ,HAS_RETURN , RET_TYPE(unsigned int) , bitsPerPixel )\ 24 | X0(getDesktopMode , FUNCTION ,HAS_RETURN , RET_CTOR , sf::VideoMode::getDesktopMode) \ 25 | X1(setWidth , SETTER , NO_RETURN , RET_NONE , width , unsigned int ,NO_POINTER)\ 26 | X1(setHeight , SETTER , NO_RETURN , RET_NONE , height , unsigned int ,NO_POINTER)\ 27 | X1(setBitsPerPixel , SETTER , NO_RETURN , RET_NONE , bitsPerPixel , unsigned int ,NO_POINTER)\ 28 | 29 | //X3(new , FUNCTION ,HAS_RETURN , RET_CTOR , sf::VideoMode, unsigned int ,NO_POINTER, unsigned int ,NO_POINTER, unsigned int ,NO_POINTER) \ 30 | 31 | #define __GO_FOR_IMPLEMENTATION__ 32 | #include "../../bindingHelper/macro2.hpp" 33 | 34 | FUNCTION_TO_BIND 35 | 36 | #undef __GO_FOR_IMPLEMENTATION__ 37 | #include "../../bindingHelper/macro2.hpp" 38 | 39 | luaL_Reg sfVideoMode_regs[] = 40 | { 41 | LUA_DEFAULT_CLASS_FUNC(sfVideoMode) 42 | FUNCTION_TO_BIND 43 | { NULL, NULL } 44 | }; 45 | 46 | LUA_REGISTER_CLASS(sfVideoMode) 47 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_videomode.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | 6 | void register_sfVideoMode(lua_State * l); 7 | 8 | 9 | #include "../../bindingHelper/lua_template.hpp" 10 | template <> 11 | const char* metaTableName(); 12 | 13 | #include "../../bindingHelper/lua_template.hpp" 14 | template <> 15 | const char* metaTableName(); 16 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_window.cpp: -------------------------------------------------------------------------------- 1 | #include "wrap_window.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #define TYPE_TO_BIND sf::Window 7 | #define NAME_TO_BIND sfWindow 8 | 9 | #include "../../bindingHelper/marco.hpp" 10 | #include "../../bindingHelper/macro2.hpp" 11 | #include "../../bindingHelper/lua_template.hpp" 12 | #include "../../bindingHelper/enum.hpp" 13 | 14 | #include "../system/wrap_vector2i.h" 15 | #include "../system/wrap_vector2u.h" 16 | #include "../window/wrap_event.h" 17 | #include "../window/wrap_videomode.h" 18 | 19 | void register_WindowEnums(lua_State * l) 20 | { 21 | add_enum_to_lua(l,"sfWindowStyle", 22 | "None" , sf::Style::None, 23 | "Titlebar" , sf::Style::Titlebar, 24 | "Resize" , sf::Style::Resize, 25 | "Close" , sf::Style::Close, 26 | "Fullscreen" , sf::Style::Fullscreen, 27 | "Default" , sf::Style::Default, 28 | nullptr); 29 | 30 | } 31 | 32 | 33 | DEFAULT_CTOR_3(sf::Window,sf::VideoMode,IS_POINTER,std::string,NO_POINTER,unsigned int,NO_POINTER) 34 | 35 | IMPLEMENT_LUA_CLASS(sfWindow,sf::Window) 36 | 37 | #define FUNCTION_TO_BIND \ 38 | X0(isOpen , METHOD , HAS_RETURN , RET_TYPE(bool) , isOpen ) \ 39 | X0(close , METHOD , NO_RETURN , RET_NONE , close ) \ 40 | X0(display , METHOD , NO_RETURN , RET_NONE , display ) \ 41 | X0(getPosition , METHOD , HAS_RETURN , RET_TYPE(sf::Vector2i) , getPosition ) \ 42 | X1(setPosition , METHOD ,NO_RETURN , RET_NONE , setPosition , sf::Vector2i , IS_POINTER )\ 43 | X0(getSize , METHOD , HAS_RETURN , RET_TYPE(sf::Vector2u) , getSize ) \ 44 | X1(setSize , METHOD ,NO_RETURN , RET_NONE , setSize , sf::Vector2u , IS_POINTER )\ 45 | X1(setTitle , METHOD ,NO_RETURN , RET_NONE , setTitle , std::string , NO_POINTER )\ 46 | X1(setVisible , METHOD ,NO_RETURN , RET_NONE , setVisible , bool , NO_POINTER )\ 47 | X1(setVerticalSyncEnabled , METHOD ,NO_RETURN , RET_NONE , setVerticalSyncEnabled , bool , NO_POINTER )\ 48 | X1(setMouseCursorVisible , METHOD ,NO_RETURN , RET_NONE , setMouseCursorVisible , bool , NO_POINTER )\ 49 | X1(setKeyRepeatEnabled , METHOD ,NO_RETURN , RET_NONE , setKeyRepeatEnabled , bool , NO_POINTER )\ 50 | X1(setJoystickThreshold , METHOD ,NO_RETURN , RET_NONE , setJoystickThreshold , bool , NO_POINTER )\ 51 | X1(setActive , METHOD ,NO_RETURN , RET_NONE , setActive , bool , NO_POINTER )\ 52 | X1(setFramerateLimit , METHOD ,NO_RETURN , RET_NONE , setFramerateLimit , unsigned int , NO_POINTER )\ 53 | X1(pollEvent , METHOD ,HAS_RETURN , RET_TYPE(bool) , pollEvent , sf::Event , IS_POINTER )\ 54 | X1(waitEvent , METHOD ,HAS_RETURN , RET_TYPE(bool) , waitEvent , sf::Event , IS_POINTER )\ 55 | X3(create , METHOD , NO_RETURN , RET_NONE , create , sf::VideoMode , IS_POINTER , std::string , NO_POINTER, unsigned int , NO_POINTER)\ 56 | 57 | //X0(getSetting , METHOD , HAS_RETURN , RET_TYPE(sf::ContextSettings) , getSetting ) \ 58 | //X1(setIcon , METHOD ,NO_RETURN , RET_NONE , setIcon , bool , NO_POINTER )\ 59 | //X1(waitEvent , METHOD ,NO_RETURN , RET_NONE , setIcon , bool , NO_POINTER )\ 60 | 61 | #define __GO_FOR_IMPLEMENTATION__ 62 | #include "../../bindingHelper/macro2.hpp" 63 | 64 | FUNCTION_TO_BIND 65 | 66 | #undef __GO_FOR_IMPLEMENTATION__ 67 | #include "../../bindingHelper/macro2.hpp" 68 | 69 | int sfWindow_pollEvent(lua_State* l); 70 | 71 | luaL_Reg sfWindow_regs[] = 72 | { 73 | LUA_DEFAULT_CLASS_FUNC(sfWindow) 74 | FUNCTION_TO_BIND 75 | { NULL, NULL } 76 | }; 77 | 78 | LUA_REGISTER_CLASS(sfWindow) 79 | 80 | -------------------------------------------------------------------------------- /src/sfml/window/wrap_window.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void register_WindowEnums(lua_State * l); 6 | 7 | 8 | void register_sfWindow(lua_State * l); 9 | 10 | 11 | #include "../../bindingHelper/lua_template.hpp" 12 | template <> 13 | const char* metaTableName(); 14 | 15 | #include "../../bindingHelper/lua_template.hpp" 16 | template <> 17 | const char* metaTableName(); 18 | --------------------------------------------------------------------------------