Browse Source

Merge branch 'master' of http://github.com/Gambini/libRocket into feature/lua-scripting

# By Nate Starkey (51) and others
# Via Gambini (4) and others
* 'master' of git://github.com/Gambini/libRocket: (55 commits)
  Added global rocket.key_identifier and rocket.key_modifier
  Updated to Lua 5.2
  Apply fix from commit 14c5eaac0bf9505084f9fd0c64606af0845de856 to luainvaders:     "create ShellRenderInterfaceOpenGL::SetViewport, instead of hardcoding     the height of the screen for scissoring. anything that would overflow     y with scrollbars would result in being cut off by a the difference between     768 and the viewports current resolution. even the debugger was broken."
  Oops - fixed build problem with Python bindings
  Use Rocket::Core::FileInterface to load scripts.
  Fixed the install issue.
  Made ElementStyle in to ElementStyleProxy.
  Fixed the names of the .lib files to match cmake.
  add luainvaders to CMakeLists.txt
  Part of SampleFileList was not auto generated, now it is.
  Remove warnings and errors for clang and g++
  Got cmake to work for msvc
  Also applied the previous fix to RocketControlsLua
  Fixed compile errors with xcode.
  Fixed the rocket global variable that I broke with the last commit.
  One last proxy table, rocket.contexts
  Made the proxy tables act just like regular tables
  Hopefully last set of bug fixes/features.
  Added Lua to the scripting types in the readme
  Removed Lua5.1 from the repo
  ...

Conflicts:
	Build/CMakeLists.txt
	Build/RocketCore.vcproj
	Build/cmake/FileList.cmake
	Build/cmake/gen_samplelists.sh
David Wimsey 11 years ago
parent
commit
e148bd5dfc
100 changed files with 8880 additions and 5 deletions
  1. 66 1
      Build/CMakeLists.txt
  2. 108 2
      Build/cmake/FileList.cmake
  3. 190 0
      Build/cmake/FindLua.cmake
  4. 37 1
      Build/cmake/SampleFileList.cmake
  5. 19 0
      Build/cmake/gen_filelists.sh
  6. 1 1
      Build/cmake/gen_samplelists.sh
  7. 45 0
      Include/Rocket/Controls/Lua/Controls.h
  8. 53 0
      Include/Rocket/Controls/Lua/Header.h
  9. 53 0
      Include/Rocket/Core/Lua/Header.h
  10. 121 0
      Include/Rocket/Core/Lua/Interpreter.h
  11. 190 0
      Include/Rocket/Core/Lua/LuaType.h
  12. 343 0
      Include/Rocket/Core/Lua/LuaType.inl
  13. 83 0
      Include/Rocket/Core/Lua/Utilities.h
  14. 34 0
      Include/Rocket/Core/Lua/lua.hpp
  15. 35 0
      Samples/luainvaders/data/background.rml
  16. BIN
      Samples/luainvaders/data/background.tga
  17. 126 0
      Samples/luainvaders/data/game.rml
  18. 55 0
      Samples/luainvaders/data/help.rml
  19. BIN
      Samples/luainvaders/data/help_defender.tga
  20. BIN
      Samples/luainvaders/data/help_invader_mothership.tga
  21. BIN
      Samples/luainvaders/data/help_invader_rank1.tga
  22. BIN
      Samples/luainvaders/data/help_invader_rank2.tga
  23. BIN
      Samples/luainvaders/data/help_invader_rank3.tga
  24. 76 0
      Samples/luainvaders/data/high_score.rml
  25. BIN
      Samples/luainvaders/data/high_scores_defender.tga
  26. BIN
      Samples/luainvaders/data/invaders.tga
  27. 23 0
      Samples/luainvaders/data/logo.rml
  28. BIN
      Samples/luainvaders/data/logo.tga
  29. 38 0
      Samples/luainvaders/data/main_menu.rml
  30. 119 0
      Samples/luainvaders/data/options.rml
  31. 27 0
      Samples/luainvaders/data/pause.rml
  32. 71 0
      Samples/luainvaders/data/start_game.rml
  33. 24 0
      Samples/luainvaders/data/window.rml
  34. 40 0
      Samples/luainvaders/lua/start.lua
  35. 86 0
      Samples/luainvaders/src/DecoratorDefender.cpp
  36. 57 0
      Samples/luainvaders/src/DecoratorDefender.h
  37. 67 0
      Samples/luainvaders/src/DecoratorInstancerDefender.cpp
  38. 56 0
      Samples/luainvaders/src/DecoratorInstancerDefender.h
  39. 78 0
      Samples/luainvaders/src/DecoratorInstancerStarfield.cpp
  40. 57 0
      Samples/luainvaders/src/DecoratorInstancerStarfield.h
  41. 145 0
      Samples/luainvaders/src/DecoratorStarfield.cpp
  42. 82 0
      Samples/luainvaders/src/DecoratorStarfield.h
  43. 182 0
      Samples/luainvaders/src/Defender.cpp
  44. 81 0
      Samples/luainvaders/src/Defender.h
  45. 102 0
      Samples/luainvaders/src/ElementGame.cpp
  46. 64 0
      Samples/luainvaders/src/ElementGame.h
  47. 28 0
      Samples/luainvaders/src/ElementGameInstancer.cpp
  48. 23 0
      Samples/luainvaders/src/ElementGameInstancer.h
  49. 445 0
      Samples/luainvaders/src/Game.cpp
  50. 128 0
      Samples/luainvaders/src/Game.h
  51. 148 0
      Samples/luainvaders/src/GameDetails.cpp
  52. 107 0
      Samples/luainvaders/src/GameDetails.h
  53. 236 0
      Samples/luainvaders/src/HighScores.cpp
  54. 77 0
      Samples/luainvaders/src/HighScores.h
  55. 266 0
      Samples/luainvaders/src/Invader.cpp
  56. 114 0
      Samples/luainvaders/src/Invader.h
  57. 117 0
      Samples/luainvaders/src/LuaInterface.cpp
  58. 27 0
      Samples/luainvaders/src/LuaInterface.h
  59. 84 0
      Samples/luainvaders/src/Mothership.cpp
  60. 53 0
      Samples/luainvaders/src/Mothership.h
  61. 188 0
      Samples/luainvaders/src/Shield.cpp
  62. 90 0
      Samples/luainvaders/src/Shield.h
  63. 52 0
      Samples/luainvaders/src/Sprite.cpp
  64. 50 0
      Samples/luainvaders/src/Sprite.h
  65. 198 0
      Samples/luainvaders/src/main.cpp
  66. 72 0
      Source/Controls/Lua/As.h
  67. 81 0
      Source/Controls/Lua/Controls.cpp
  68. 121 0
      Source/Controls/Lua/DataFormatter.cpp
  69. 58 0
      Source/Controls/Lua/DataFormatter.h
  70. 151 0
      Source/Controls/Lua/DataSource.cpp
  71. 63 0
      Source/Controls/Lua/DataSource.h
  72. 119 0
      Source/Controls/Lua/ElementDataGrid.cpp
  73. 62 0
      Source/Controls/Lua/ElementDataGrid.h
  74. 133 0
      Source/Controls/Lua/ElementDataGridRow.cpp
  75. 66 0
      Source/Controls/Lua/ElementDataGridRow.h
  76. 88 0
      Source/Controls/Lua/ElementForm.cpp
  77. 56 0
      Source/Controls/Lua/ElementForm.h
  78. 131 0
      Source/Controls/Lua/ElementFormControl.cpp
  79. 62 0
      Source/Controls/Lua/ElementFormControl.h
  80. 82 0
      Source/Controls/Lua/ElementFormControlDataSelect.cpp
  81. 55 0
      Source/Controls/Lua/ElementFormControlDataSelect.h
  82. 191 0
      Source/Controls/Lua/ElementFormControlInput.cpp
  83. 68 0
      Source/Controls/Lua/ElementFormControlInput.h
  84. 134 0
      Source/Controls/Lua/ElementFormControlSelect.cpp
  85. 63 0
      Source/Controls/Lua/ElementFormControlSelect.h
  86. 150 0
      Source/Controls/Lua/ElementFormControlTextArea.cpp
  87. 64 0
      Source/Controls/Lua/ElementFormControlTextArea.h
  88. 131 0
      Source/Controls/Lua/ElementTabSet.cpp
  89. 64 0
      Source/Controls/Lua/ElementTabSet.h
  90. 100 0
      Source/Controls/Lua/LuaDataFormatter.cpp
  91. 55 0
      Source/Controls/Lua/LuaDataFormatter.h
  92. 113 0
      Source/Controls/Lua/LuaDataSource.cpp
  93. 71 0
      Source/Controls/Lua/LuaDataSource.h
  94. 136 0
      Source/Controls/Lua/SelectOptionsProxy.cpp
  95. 57 0
      Source/Controls/Lua/SelectOptionsProxy.h
  96. 35 0
      Source/Controls/Lua/precompiled.h
  97. 238 0
      Source/Core/Lua/Colourb.cpp
  98. 68 0
      Source/Core/Lua/Colourb.h
  99. 210 0
      Source/Core/Lua/Colourf.cpp
  100. 67 0
      Source/Core/Lua/Colourf.h

+ 66 - 1
Build/CMakeLists.txt

@@ -56,6 +56,7 @@ if(NOT IOS)
 endif(NOT IOS)
 
 option(BUILD_PYTHON_BINDINGS "Build python bindings" OFF)
+option(BUILD_LUA_BINDINGS "Build Lua bindings" OFF)
 option(BUILD_SAMPLES "Build samples" OFF)
 if(WIN32)
 	option(SKIP_DIRECTX_SAMPLES "Skip build of all DirectX related samples.  Only applies if BUILD_SAMPLES is ON" OFF)
@@ -125,6 +126,15 @@ if(BUILD_PYTHON_BINDINGS)
 
 endif()
 
+#Lua
+if(BUILD_LUA_BINDINGS)
+    find_package(Lua )
+    if(LUA_FOUND)
+        include_directories(${LUA_INCLUDE_DIR})
+        list(APPEND LUA_BINDINGS_LINK_LIBS ${LUA_LIBRARIES})
+    endif()
+endif()
+
 
 #===================================
 # Setup paths ======================
@@ -194,6 +204,31 @@ if(BUILD_PYTHON_BINDINGS)
     endforeach(library)
 endif()
 
+# Build Lua bindings
+if(BUILD_LUA_BINDINGS)
+    set(LIBRARIES Core Controls)
+
+    foreach(library ${LIBRARIES})
+        set(NAME Rocket${library}Lua)
+
+        add_library(${NAME} ${Lua${library}_SRC_FILES}
+                            ${Lua${library}_HDR_FILES}
+                            ${Lua${library}_PUB_HDR_FILES}
+        )
+
+        set_target_properties(${NAME} PROPERTIES
+                           VERSION ${PROJECT_VERSION}
+                           SOVERSION ${LIBROCKET_VERSION_MAJOR}
+        )
+        
+        install(TARGETS ${NAME}
+            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+        )
+    endforeach(library)
+endif()
+
 
 #===================================
 # Link libraries ===================
@@ -208,6 +243,11 @@ if(BUILD_PYTHON_BINDINGS)
     target_link_libraries(_rocketcontrols RocketControls ${PY_BINDINGS_LINK_LIBS})
 endif()
 
+if(BUILD_LUA_BINDINGS)
+    target_link_libraries(RocketCoreLua RocketCore ${LUA_BINDINGS_LINK_LIBS})
+    target_link_libraries(RocketControlsLua RocketControls RocketCoreLua ${LUA_BINDINGS_LINK_LIBS})
+endif()
+
 
 #===================================
 # Build samples ====================
@@ -388,6 +428,14 @@ if(BUILD_SAMPLES)
 	    	RUNTIME DESTINATION ${SAMPLES_DIR}/pyinvaders
 	    	BUNDLE DESTINATION ${SAMPLES_DIR})
 	endif()
+    
+    if(BUILD_LUA_BINDINGS)
+        bl_sample(luainvaders RocketCoreLua RocketControlsLua ${sample_LIBRARIES} ${LUA_BINDINGS_LINK_LIBS})
+        install(DIRECTORY DESTINATION ${SAMPLES_DIR}/luainvaders)
+        install(TARGETS luainvaders 
+        	RUNTIME DESTINATION ${SAMPLES_DIR}/luainvaders
+        	BUNDLE DESTINATION ${SAMPLES_DIR})
+    endif()
 endif()
 
 
@@ -401,11 +449,20 @@ if(BUILD_PYTHON_BINDINGS)
     )
     install(DIRECTORY ${PROJECT_SOURCE_DIR}/Include/Rocket
             DESTINATION include
+            PATTERN "Lua" EXCLUDE
+    )
+endif()
+if(BUILD_LUA_BINDINGS)
+    install(DIRECTORY ${PROJECT_SOURCE_DIR}/Include/Rocket
+            DESTINATION include
+            PATTERN "Python" EXCLUDE
     )
-else()
+endif()
+if(NOT BUILD_LUA_BINDINGS AND NOT BUILD_PYTHON_BINDINGS)
     install(DIRECTORY ${PROJECT_SOURCE_DIR}/Include/Rocket
             DESTINATION include
             PATTERN "Python" EXCLUDE
+            PATTERN "Lua" EXCLUDE
     )
 endif()
 
@@ -439,4 +496,12 @@ if(BUILD_SAMPLES)
     install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/assets
             DESTINATION ${SAMPLES_DIR}
     )
+    if(BUILD_LUA_BINDINGS)
+    install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/luainvaders/data 
+            DESTINATION ${SAMPLES_DIR}/luainvaders
+    )
+    install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/luainvaders/lua 
+            DESTINATION ${SAMPLES_DIR}/luainvaders
+    )
+    endif()
 endif()

+ 108 - 2
Build/cmake/FileList.cmake

@@ -432,7 +432,6 @@ set(Pycore_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ContextInterface.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ContextProxy.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/Converters.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/Python/DataSourceWrapper.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ElementAttributeProxy.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ElementChildrenProxy.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ElementDocumentWrapper.h
@@ -467,7 +466,6 @@ set(Pycore_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ContextInterface.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ContextProxy.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/Converters.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/Python/DataSourceWrapper.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ElementAttributeProxy.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ElementChildrenProxy.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Python/ElementDocumentWrapper.cpp
@@ -507,3 +505,111 @@ set(Pycontrols_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Source/Controls/Python/SelectOptionProxy.cpp
 )
 
+set(LuaCore_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Colourb.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Colourf.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Context.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ContextDocumentsProxy.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Document.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Element.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementAttributesProxy.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementChildNodesProxy.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementInstancer.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementStyleProxy.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementText.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Event.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/EventParametersProxy.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/GlobalLuaFunctions.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Log.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaDocument.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaDocumentElementInstancer.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaElement.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaElementInstancer.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaEventListener.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaEventListenerInstancer.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/precompiled.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Rocket.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/RocketContextsProxy.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Vector2f.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Vector2i.h
+)
+
+set(LuaCore_PUB_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/Lua/Header.h
+    ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/Lua/Interpreter.h
+    ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/Lua/LuaType.h
+    ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/Lua/Utilities.h
+)
+
+set(LuaCore_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Colourb.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Colourf.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Context.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ContextDocumentsProxy.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Document.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Element.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementAttributesProxy.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementChildNodesProxy.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementInstancer.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementStyleProxy.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/ElementText.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Event.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/EventParametersProxy.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/GlobalLuaFunctions.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Interpreter.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Log.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaDocument.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaDocumentElementInstancer.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaElementInstancer.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaEventListener.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/LuaEventListenerInstancer.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/precompiled.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Rocket.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/RocketContextsProxy.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Utilities.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Vector2f.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/Lua/Vector2i.cpp
+)
+
+set(LuaControls_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/As.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/DataFormatter.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/DataSource.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementDataGrid.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementDataGridRow.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementForm.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControl.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControlDataSelect.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControlInput.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControlSelect.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControlTextArea.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementTabSet.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/LuaDataFormatter.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/LuaDataSource.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/precompiled.h
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/SelectOptionsProxy.h
+)
+
+set(LuaControls_PUB_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Include/Rocket/Controls/Lua/Controls.h
+    ${PROJECT_SOURCE_DIR}/Include/Rocket/Controls/Lua/Header.h
+)
+
+set(LuaControls_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/Controls.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/DataFormatter.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/DataSource.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementDataGrid.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementDataGridRow.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementForm.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControl.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControlDataSelect.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControlInput.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControlSelect.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementFormControlTextArea.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/ElementTabSet.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/LuaDataFormatter.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/LuaDataSource.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Controls/Lua/SelectOptionsProxy.cpp
+)
+

+ 190 - 0
Build/cmake/FindLua.cmake

@@ -0,0 +1,190 @@
+#.rst:
+# FindLua
+# -------
+#
+#
+#
+# Locate Lua library This module defines
+#
+# ::
+#
+#   LUA_FOUND          - if false, do not try to link to Lua
+#   LUA_LIBRARIES      - both lua and lualib
+#   LUA_INCLUDE_DIR    - where to find lua.h
+#   LUA_VERSION_STRING - the version of Lua found
+#   LUA_VERSION_MAJOR  - the major version of Lua
+#   LUA_VERSION_MINOR  - the minor version of Lua
+#   LUA_VERSION_PATCH  - the patch version of Lua
+#
+#
+#
+# Note that the expected include convention is
+#
+# ::
+#
+#   #include "lua.h"
+#
+# and not
+#
+# ::
+#
+#   #include <lua/lua.h>
+#
+# This is because, the lua location is not standardized and may exist in
+# locations other than lua/
+
+#=============================================================================
+# Copyright 2007-2009 Kitware, Inc.
+# Copyright 2013 Rolf Eike Beer <[email protected]>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 
+# * Neither the names of Kitware, Inc., the Insight Software Consortium,
+# nor the names of their contributors may be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#===========================================================================
+
+unset(_lua_include_subdirs)
+unset(_lua_library_names)
+
+# this is a function only to have all the variables inside go away automatically
+function(set_lua_version_vars)
+    set(LUA_VERSIONS5 5.3 5.2 5.1 5.0)
+
+    if (Lua_FIND_VERSION_EXACT)
+        if (Lua_FIND_VERSION_COUNT GREATER 1)
+            set(lua_append_versions ${Lua_FIND_VERSION_MAJOR} ${Lua_FIND_VERSION_MINOR})
+        endif ()
+    elseif (Lua_FIND_VERSION)
+        # once there is a different major version supported this should become a loop
+        if (NOT Lua_FIND_VERSION_MAJOR GREATER 5)
+            if (Lua_FIND_VERSION_COUNT EQUAL 1)
+                set(lua_append_versions ${LUA_VERSIONS5})
+            else ()
+                foreach (subver IN LISTS LUA_VERSIONS5)
+                    if (NOT subver VERSION_LESS ${Lua_FIND_VERSION})
+                        list(APPEND lua_append_versions ${subver})
+                    endif ()
+                endforeach ()
+            endif ()
+        endif ()
+    else ()
+        # once there is a different major version supported this should become a loop
+        set(lua_append_versions ${LUA_VERSIONS5})
+    endif ()
+
+    foreach (ver IN LISTS lua_append_versions)
+        string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}")
+        list(APPEND _lua_include_subdirs
+             include/lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
+             include/lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+             include/lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+        )
+        list(APPEND _lua_library_names
+             lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
+             lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+             lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+        )
+    endforeach ()
+
+    set(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE)
+    set(_lua_library_names "${_lua_library_names}" PARENT_SCOPE)
+endfunction(set_lua_version_vars)
+
+set_lua_version_vars()
+
+find_path(LUA_INCLUDE_DIR lua.h
+  HINTS
+    ENV LUA_DIR
+  PATH_SUFFIXES ${_lua_include_subdirs} include/lua include
+  PATHS
+  ~/Library/Frameworks
+  /Library/Frameworks
+  /sw # Fink
+  /opt/local # DarwinPorts
+  /opt/csw # Blastwave
+  /opt
+)
+unset(_lua_include_subdirs)
+
+find_library(LUA_LIBRARY
+  NAMES ${_lua_library_names} lua
+  HINTS
+    ENV LUA_DIR
+  PATH_SUFFIXES lib
+  PATHS
+  ~/Library/Frameworks
+  /Library/Frameworks
+  /sw
+  /opt/local
+  /opt/csw
+  /opt
+)
+unset(_lua_library_names)
+
+if (LUA_LIBRARY)
+    # include the math library for Unix
+    if (UNIX AND NOT APPLE AND NOT BEOS)
+        find_library(LUA_MATH_LIBRARY m)
+        set(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}")
+    # For Windows and Mac, don't need to explicitly include the math library
+    else ()
+        set(LUA_LIBRARIES "${LUA_LIBRARY}")
+    endif ()
+endif ()
+
+if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
+    # At least 5.[012] have different ways to express the version
+    # so all of them need to be tested. Lua 5.2 defines LUA_VERSION
+    # and LUA_RELEASE as joined by the C preprocessor, so avoid those.
+    file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_strings
+         REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*")
+
+    string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};")
+    if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$")
+        string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};")
+        string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};")
+        set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
+    else ()
+        string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
+        if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$")
+            string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};")
+        endif ()
+        string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}")
+        string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}")
+        string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}")
+    endif ()
+
+    unset(lua_version_strings)
+endif()
+
+include(FindPackageHandleStandardArgs)
+# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
+# all listed variables are TRUE
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
+                                  REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
+                                  VERSION_VAR LUA_VERSION_STRING)
+
+mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY)

+ 37 - 1
Build/cmake/SampleFileList.cmake

@@ -113,6 +113,43 @@ set(invaders_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/Sprite.cpp
 )
 
+set(luainvaders_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/DecoratorDefender.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/DecoratorInstancerDefender.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/DecoratorInstancerStarfield.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/DecoratorStarfield.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Defender.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/ElementGame.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/ElementGameInstancer.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Game.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/GameDetails.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/HighScores.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Invader.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/LuaInterface.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Mothership.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Shield.h
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Sprite.h
+)
+
+set(luainvaders_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/DecoratorDefender.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/DecoratorInstancerDefender.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/DecoratorInstancerStarfield.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/DecoratorStarfield.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Defender.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/ElementGame.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/ElementGameInstancer.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Game.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/GameDetails.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/HighScores.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Invader.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/LuaInterface.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/main.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Mothership.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Shield.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/luainvaders/src/Sprite.cpp
+)
+
 set(pyinvaders_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Samples/pyinvaders/src/DecoratorDefender.h
     ${PROJECT_SOURCE_DIR}/Samples/pyinvaders/src/DecoratorInstancerDefender.h
@@ -235,4 +272,3 @@ else()
                ${PROJECT_SOURCE_DIR}/Samples/shell/include/x11/InputX11.h
        )
 endif()
-

+ 19 - 0
Build/cmake/gen_filelists.sh

@@ -10,6 +10,7 @@ srcdir='${PROJECT_SOURCE_DIR}'
 srcpath=Source
 hdrpath=Include/Rocket
 pypath=Python
+luapath=Lua
 
 printfiles() {
     # Print headers
@@ -45,6 +46,21 @@ printpyfiles() {
     echo -e ')\n' >>$file
 }
 
+printluafiles() {
+    # Print headers
+    echo ${hdr/lib/Lua${1}} >>$file
+    find  $srcpath/$1/$luapath -iname "*.h" -exec echo '    '$srcdir/{} \; 2>/dev/null | sort -f >>$file
+    echo -e ')\n' >>$file
+    # Print public headers
+    echo ${pubhdr/lib/Lua${1}} >>$file
+    find  $hdrpath/$1/$luapath -iname "*.h" -exec echo '    '$srcdir/{} \; 2>/dev/null | sort -f >>$file 2>/dev/null
+    echo -e ')\n' >>$file
+    # Print source files
+    echo ${src/lib/Lua${1}} >>$file
+    find  $srcpath/$1/$luapath -iname "*.cpp" -exec echo '    '$srcdir/{} \; 2>/dev/null | sort -f >>$file
+    echo -e ')\n' >>$file
+}
+
 pushd $basedir
 echo -e "# This file was auto-generated with gen_filelists.sh\n" >$file
 for lib in "Core" "Controls" "Debugger"; do
@@ -54,5 +70,8 @@ done
 for lib in "Core" "Controls"; do
     printpyfiles $lib
 done
+for lib in "Core" "Controls"; do
+    printluafiles $lib
+done
 popd
 

+ 1 - 1
Build/cmake/gen_samplelists.sh

@@ -7,7 +7,7 @@ hdr='set(sample_HDR_FILES'
 srcdir='${PROJECT_SOURCE_DIR}'
 srcpath=Samples
 samples=('basic/customlog' 'basic/directx' 'basic/drag' 'basic/loaddocument'
-        'basic/ogre3d' 'basic/treeview' 'invaders' 'pyinvaders' 'shell'
+        'basic/ogre3d' 'basic/treeview' 'invaders' 'luainvaders' 'pyinvaders' 'shell'
 	'tutorial/template' 'tutorial/datagrid' 'tutorial/datagrid_tree' 'tutorial/tutorial_drag'
 )
 

+ 45 - 0
Include/Rocket/Controls/Lua/Controls.h

@@ -0,0 +1,45 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETCONTROLSLUACONTROLS_H
+#define ROCKETCONTROLSLUACONTROLS_H
+
+#include <Rocket/Controls/Lua/Header.h>
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+/** Doxygen doesn't like to get the namespace, so the full name is
+@c Rocket::Controls::Lua::RegisterTypes.
+This will define all of the types from RocketControls for Lua. 
+@sa Rocket::Core::Lua::Interpreter::RegisterCoreTypes(lua_State*)
+@relatesalso Rocket::Core::Lua::Interpreter*/
+void ROCKETLUA_API RegisterTypes(lua_State* L);
+}
+}
+}
+#endif

+ 53 - 0
Include/Rocket/Controls/Lua/Header.h

@@ -0,0 +1,53 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAHEADER_H
+#define ROCKETCONTROLSLUAHEADER_H
+
+#include <Rocket/Core/Platform.h>
+
+#ifdef ROCKETLUA_API
+#undef ROCKETLUA_API
+#endif
+
+#if !defined STATIC_LIB
+	#ifdef ROCKET_PLATFORM_WIN32
+		#if defined RocketcoreLua_EXPORTS 
+			#define ROCKETLUA_API __declspec(dllexport)
+        #elif defined RocketcontrolsLua_EXPORTS
+            #define ROCKETLUA_API __declspec(dllexport)
+        #else
+			#define ROCKETLUA_API __declspec(dllimport)
+		#endif
+	#else
+		#define ROCKETLUA_API __attribute__((visibility("default")))
+	#endif
+#else
+	#define ROCKETLUA_API
+#endif
+
+#endif

+ 53 - 0
Include/Rocket/Core/Lua/Header.h

@@ -0,0 +1,53 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCORELUAHEADER_H
+#define ROCKETCORELUAHEADER_H
+
+#include <Rocket/Core/Platform.h>
+
+#ifdef ROCKETLUA_API
+#undef ROCKETLUA_API
+#endif
+
+#if !defined STATIC_LIB
+	#ifdef ROCKET_PLATFORM_WIN32
+		#if defined RocketcoreLua_EXPORTS 
+			#define ROCKETLUA_API __declspec(dllexport)
+        #elif defined RocketcontrolsLua_EXPORTS
+            #define ROCKETLUA_API __declspec(dllexport)
+        #else
+			#define ROCKETLUA_API __declspec(dllimport)
+		#endif
+	#else
+		#define ROCKETLUA_API __attribute__((visibility("default")))
+	#endif
+#else
+	#define ROCKETLUA_API
+#endif
+
+#endif

+ 121 - 0
Include/Rocket/Core/Lua/Interpreter.h

@@ -0,0 +1,121 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCORELUAINTERPRETER_H
+#define ROCKETCORELUAINTERPRETER_H 
+
+#include "Header.h"
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Plugin.h>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+/**
+    This initializes the Lua interpreter, and has functions to load the scripts or
+    call functions that exist in Lua.
+
+    @author Nathan Starkey
+*/
+class ROCKETLUA_API Interpreter : public Plugin
+{
+public:
+    /** This function calls luaL_loadfile and then lua_pcall, reporting the errors (if any)
+    @param[in] file Fully qualified file name to execute.
+    @remark Somewhat misleading name if you are used to the Lua meaning of "load file". It behaves
+    exactly as luaL_dofile does.            */
+    static void LoadFile(const Rocket::Core::String& file);
+    /** Calls lua_dostring and reports the errors.
+    @param[in] code String to execute
+    @param[in] name Name for the code that will show up in the Log  */
+    static void DoString(const Rocket::Core::String& code, const Rocket::Core::String& name = "");
+    /** Same as DoString, except does NOT call pcall on it. It will leave the compiled (but not executed) string
+    on top of the stack. It behaves exactly like luaL_loadstring, but you get to specify the name
+    @param[in] code String to compile
+    @param[in] name Name for the code that will show up in the Log    */
+    static void LoadString(const Rocket::Core::String& code, const Rocket::Core::String& name = "");
+
+    /** Clears all of the items on the stack, and pushes the function from funRef on top of the stack. Only use
+    this if you used lua_ref instead of luaL_ref
+    @param[in] funRef Lua reference that you would recieve from calling lua_ref   */
+    static void BeginCall(int funRef);
+    /** Uses lua_pcall on a function, which executes the function with params number of parameters and pushes
+    res number of return values on to the stack.
+    @pre Before you call this, your stack should look like:
+    [1] function to call; 
+    [2...top] parameters to pass to the function (if any).
+    Or, in words, make sure to push the function on the stack before the parameters.
+    @post After this function, the params and function will be popped off, and 'res' 
+    number of items will be pushed.     */
+    static bool ExecuteCall(int params = 0, int res = 0);
+    /** removes 'res' number of items from the stack
+    @param[in] res Number of results to remove from the stack.   */
+    static void EndCall(int res = 0);
+
+    /** This will populate the global Lua table with all of the Lua core types by calling LuaType<T>::Register
+    @param[in] L The lua_State to use to register the types
+    @remark This is called automatically inside of Interpreter::Startup(), so you do not have to 
+    call this function upon initialization of the Interpreter. If you are using RocketControlsLua, then you
+    \em will need to call Rocket::Controls::Lua::RegisterTypes(lua_State*)     */
+    static void RegisterCoreTypes(lua_State* L);
+
+    /** 
+    @return The lua_State that the Interpreter created in Interpreter::Startup()
+    @remark This class lacks a SetLuaState for a reason. If you have to use a seperate Lua binding and want to keep the types
+    from libRocket, then use this lua_State; it will already have all of the libraries loaded, and all of the types defined.
+    Alternatively, you can call RegisterCoreTypes(lua_State*) with your own Lua state if you need them defined in it. */
+    static lua_State* GetLuaState();
+
+    /** Creates the plugin. 
+    @remark Call this function only once. Only call it more than once if you call Interpreter::Shutdown() and need to have this
+    exist again. Internally, it calls Interpreter::Startup() and registers the "body" tag to generate a LuaDocument
+    rather than a Rocket::Core::ElementDocument    */
+    static void Initialise();
+    /** Stops the plugin by calling lua_close        */
+	static void Shutdown();
+    
+    /** @sa Rocket::Core::Plugin::GetEventClasses */
+    virtual int GetEventClasses();
+    /** @sa Rocket::Core::Plugin::OnInitialise */
+    virtual void OnInitialise();
+    /** Currently does nothing. You must call Interpreter::Shutdown yourself at the appropriate time.
+    @sa Rocket::Core::Plugin::OnShutdown    */
+    virtual void OnShutdown();
+private:
+    /** Creates a lua_State for @var _L and calls luaL_openlibs, then calls Interpreter::RegisterCoreTypes(lua_State*)
+    @remark called by Interpreter::Initialise()    */
+    void Startup();
+
+    /** Lua state that Interpreter::Initialise() creates.    */
+    static lua_State* _L;
+};
+}
+}
+}
+#endif
+

+ 190 - 0
Include/Rocket/Core/Lua/LuaType.h

@@ -0,0 +1,190 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCORELUALUATYPE_H
+#define ROCKETCORELUALUATYPE_H
+
+#include <Rocket/Core/Lua/Header.h>
+#include <Rocket/Core/Lua/lua.hpp>
+
+
+//As an example, if you used this macro like
+//LUAMETHOD(Unit,GetId)
+//it would result in code that looks like
+//{ "GetId", UnitGetId },
+//Which would force you to create a global function named UnitGetId in C with the correct function signature, usually int(*)(lua_State*,type*);
+#define LUAMETHOD(type,name) { #name, type##name },
+
+//See above, but the method must match the function signature int(*)(lua_State*) and as example:
+//LUAGETTER(Unit,Id) would mean you need a function named UnitGetAttrId
+//The first stack position will be the userdata
+#define LUAGETTER(type,varname) { #varname, type##GetAttr##varname },
+
+//Same method signature as above, but as example:
+//LUASETTER(Unit,Id) would mean you need a function named UnitSetAttrId
+//The first stack position will be the userdata, and the second will be value on the other side of the equal sign
+#define LUASETTER(type,varname) { #varname, type##SetAttr##varname },
+
+#define CHECK_BOOL(L,narg) (lua_toboolean((L),(narg)) > 0 ? true : false )
+#define LUACHECKOBJ(obj) if((obj) == NULL) { lua_pushnil(L); return 1; }
+
+ /** Used to remove repetitive typing at the cost of flexibility. When you use this, you @em must have 
+ functions with the same name as defined in the macro. For example, if you used @c Element as type, you would
+ have to have functions named @c ElementMethods, @c ElementGetters, @c ElementSetters that return the appropriate
+ types.
+ @param is_reference_counted true if the type inherits from Rocket::Core::ReferenceCountable, false otherwise*/
+#define LUACORETYPEDEFINE(type,is_ref_counted) \
+    template<> const char* GetTClassName<type>() { return #type; } \
+    template<> RegType<type>* GetMethodTable<type>() { return type##Methods; } \
+    template<> luaL_Reg* GetAttrTable<type>() { return type##Getters; } \
+    template<> luaL_Reg* SetAttrTable<type>() { return type##Setters; } \
+    template<> bool IsReferenceCounted<type>() { return (is_ref_counted); } \
+
+//We can't use LUACORETYPEDEFINE due to namespace issues
+#define LUACONTROLSTYPEDEFINE(type,is_ref_counted) \
+    template<> const char* GetTClassName<type>() { return #type; } \
+    template<> RegType<type>* GetMethodTable<type>() { return Rocket::Controls::Lua::type##Methods; } \
+    template<> luaL_Reg* GetAttrTable<type>() { return Rocket::Controls::Lua::type##Getters; } \
+    template<> luaL_Reg* SetAttrTable<type>() { return Rocket::Controls::Lua::type##Setters; } \
+    template<> bool IsReferenceCounted<type>() { return (is_ref_counted); } \
+
+/** Used to remove repetitive typing at the cost of flexibility. It creates function prototypes for
+getting the name of the type, method tables, and if it is reference counted.
+When you use this, you either must also use
+the LUACORETYPEDEFINE macro, or make sure that the function signatures are @em exact.*/
+#define LUACORETYPEDECLARE(type) \
+    template<> ROCKETLUA_API const char* GetTClassName<type>(); \
+    template<> ROCKETLUA_API RegType<type>* GetMethodTable<type>(); \
+    template<> ROCKETLUA_API luaL_Reg* GetAttrTable<type>(); \
+    template<> ROCKETLUA_API luaL_Reg* SetAttrTable<type>(); \
+    template<> ROCKETLUA_API bool IsReferenceCounted<type>(); \
+
+/** Used to remove repetitive typing at the cost of flexibility. It creates function prototypes for
+getting the name of the type, method tables, and if it is reference counted.
+When you use this, you either must also use
+the LUACORETYPEDEFINE macro, or make sure that the function signatures are @em exact.*/
+#define LUACONTROLSTYPEDECLARE(type) \
+    template<> ROCKETLUA_API const char* GetTClassName<type>(); \
+    template<> ROCKETLUA_API RegType<type>* GetMethodTable<type>(); \
+    template<> ROCKETLUA_API luaL_Reg* GetAttrTable<type>(); \
+    template<> ROCKETLUA_API luaL_Reg* SetAttrTable<type>(); \
+    template<> ROCKETLUA_API bool IsReferenceCounted<type>(); \
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+//replacement for luaL_Reg that uses a different function pointer signature, but similar syntax
+template<typename T>
+struct ROCKETLUA_API RegType
+{
+    const char* name;
+    int (*ftnptr)(lua_State*,T*);
+};
+
+/** For all of the methods available from Lua that call to the C functions. */
+template<typename T> ROCKETLUA_API RegType<T>* GetMethodTable();
+/** For all of the function that 'get' an attribute/property */
+template<typename T> ROCKETLUA_API luaL_Reg* GetAttrTable();
+/** For all of the functions that 'set' an attribute/property  */
+template<typename T> ROCKETLUA_API luaL_Reg* SetAttrTable();
+/** String representation of the class */
+template<typename T> ROCKETLUA_API const char* GetTClassName();
+/** bool for if it is reference counted */
+template<typename T> ROCKETLUA_API bool IsReferenceCounted();
+/** gets called from the LuaType<T>::Register function, right before @c _regfunctions.
+If you want to inherit from another class, in the function you would want
+to call @c _regfunctions<superclass>, where method is metatable_index - 1. Anything
+that has the same name in the subclass will be overwrite whatever had the 
+same name in the superclass.    */
+template<typename T> ROCKETLUA_API void ExtraInit(lua_State* L, int metatable_index);
+
+/**
+    This is mostly the definition of the Lua userdata that C++ gives to the user, plus
+    some helper functions.
+
+    @author Nathan Starkey
+*/
+template<typename T>
+class ROCKETLUA_API LuaType
+{
+public:
+    typedef int (*ftnptr)(lua_State* L, T* ptr);
+    /** replacement for luaL_Reg that uses a different function pointer signature, but similar syntax */
+    typedef struct { const char* name; ftnptr func; } RegType;
+
+    /** Registers the type T as a type in the Lua global namespace by creating a
+     metatable with the same name as the class, setting the metatmethods, and adding the 
+     functions from _regfunctions */
+    static inline void Register(lua_State *L);
+    /** Pushes on to the Lua stack a userdata representing a pointer of T
+    @param obj[in] The object to push to the stack
+    @param gc[in] If the obj should be deleted or decrease reference count upon the garbage collection
+    metamethod being called from the object in Lua
+    @return Position on the stack where the userdata resides   */
+    static inline int push(lua_State *L, T* obj, bool gc=false);
+    /** Statically casts the item at the position on the Lua stack
+    @param narg[in] Position of the item to cast on the Lua stack
+    @return A pointer to an object of type T or @c NULL   */
+    static inline T* check(lua_State* L, int narg);
+
+    /** For calling a C closure with upvalues. Used by the functions defined by RegType
+    @return The value that RegType.func returns   */
+    static inline int thunk(lua_State* L);
+    /** String representation of the pointer. Called by the __tostring metamethod  */
+    static inline void tostring(char* buff, void* obj);
+    //these are metamethods
+    /** The __gc metamethod. If the object was pushed by push(lua_State*,T*,bool) with the third
+    argument as true, it will either decrease the reference count or call delete depending on if
+    the type is reference counted. If the third argument to push was false, then this does nothing.
+    @return 0, since it pushes nothing on to the stack*/
+    static inline int gc_T(lua_State* L);
+    /** The __tostring metamethod.
+    @return 1, because it pushes a string representation of the userdata on to the stack  */
+    static inline int tostring_T(lua_State* L);
+    /** The __index metamethod. Called whenever the user attempts to access a variable that is
+    not in the immediate table. This handles the method calls and calls tofunctions in __getters    */
+    static inline int index(lua_State* L);
+    /** The __newindex metamethod. Called when the user attempts to set a variable that is not
+    int the immediate table. This handles the calls to functions in __setters  */
+    static inline int newindex(lua_State* L);
+	
+    /** Registers methods,getters,and setters to the type. In Lua, the methods exist in the Type name's 
+    metatable, and the getters exist in __getters and setters in __setters. The reason for __getters and __setters
+    is to have the objects use a 'dot' syntax for properties and a 'colon' syntax for methods.*/
+    static inline void _regfunctions(lua_State* L, int meta, int method);
+private:
+    LuaType(); //hide constructor
+
+};
+
+
+}
+}
+}
+
+#include "LuaType.inl" 
+#endif

+ 343 - 0
Include/Rocket/Core/Lua/LuaType.inl

@@ -0,0 +1,343 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+//#include "precompiled.h"
+#include <Rocket/Controls/Controls.h>
+#include <Rocket/Core/Core.h>
+#include <Rocket/Core/Lua/Utilities.h>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<typename T>
+void LuaType<T>::Register(lua_State* L)
+{
+    //for annotations, starting at 1, but it is a relative value, not always 1
+    lua_newtable(L); //[1] = table
+    int methods = lua_gettop(L); //methods = 1
+
+    luaL_newmetatable(L, GetTClassName<T>()); //[2] = metatable named <ClassName>, referred in here by ClassMT
+    int metatable = lua_gettop(L); //metatable = 2
+
+    luaL_newmetatable(L, "DO NOT TRASH"); //[3] = metatable named "DO NOT TRASH"
+    lua_pop(L,1); //remove the above metatable -> [-1 = 2]
+
+    //store method table in globals so that scripts can add functions written in Lua
+    lua_pushvalue(L, methods); //[methods = 1] -> [3] = copy (reference) of methods table
+    lua_setglobal(L, GetTClassName<T>()); // -> <ClassName> = [3 = 1], pop top [3]
+
+    //hide metatable from Lua getmetatable()
+    lua_pushvalue(L, methods); //[methods = 1] -> [3] = copy of methods table, including modifications above
+    lua_setfield(L, metatable, "__metatable"); //[metatable = 2] -> t[k] = v; t = [2 = ClassMT], k = "__metatable", v = [3 = 1]; pop [3]
+    
+    lua_pushcfunction(L, index); //index = cfunction -> [3] = cfunction
+    lua_setfield(L, metatable, "__index"); //[metatable = 2] -> t[k] = v; t = [2], k = "__index", v = cfunc; pop [3]
+
+    lua_pushcfunction(L, newindex);
+    lua_setfield(L, metatable, "__newindex");
+
+    lua_pushcfunction(L, gc_T);
+    lua_setfield(L, metatable, "__gc");
+
+    lua_pushcfunction(L, tostring_T);
+    lua_setfield(L, metatable, "__tostring");
+
+    ExtraInit<T>(L,metatable); //optionally implemented by individual types
+
+    lua_newtable(L); //for method table -> [3] = this table
+    lua_setmetatable(L, methods); //[methods = 1] -> metatable for [1] is [3]; [3] is popped off, top = [2]
+
+    _regfunctions(L,metatable,methods);
+
+    lua_pop(L, 2); //remove the two items from the stack, [1 = methods] and [2 = metatable]
+}
+
+
+template<typename T>
+int LuaType<T>::push(lua_State *L, T* obj, bool gc)
+{
+    //for annotations, starting at index 1, but it is a relative number, not always 1
+    if (!obj) { lua_pushnil(L); return lua_gettop(L); }
+    luaL_getmetatable(L, GetTClassName<T>());  // lookup metatable in Lua registry ->[1] = metatable of <ClassName>
+    if (lua_isnil(L, -1)) luaL_error(L, "%s missing metatable", GetTClassName<T>());
+    int mt = lua_gettop(L); //mt = 1
+    T** ptrHold = (T**)lua_newuserdata(L,sizeof(T**)); //->[2] = empty userdata
+    int ud = lua_gettop(L); //ud = 2
+    if(ptrHold != NULL)
+    {
+        *ptrHold = obj; 
+        lua_pushvalue(L, mt); // ->[3] = copy of [1]
+        lua_setmetatable(L, -2); //[-2 = 2] -> [2]'s metatable = [3]; pop [3]
+        char name[32];
+        tostring(name,obj);
+        lua_getfield(L,LUA_REGISTRYINDEX,"DO NOT TRASH"); //->[3] = value returned from function
+        if(lua_isnil(L,-1) ) //if [3] hasn't been created yet, then create it
+        {
+            luaL_newmetatable(L,"DO NOT TRASH"); //[4] = the new metatable
+            lua_pop(L,1); //pop [4]
+        }
+        lua_pop(L,1); //pop [3]
+        lua_getfield(L,LUA_REGISTRYINDEX,"DO NOT TRASH"); //->[3] = value returned from function
+        if(gc == false) //if we shouldn't garbage collect it, then put the name in to [3]
+        {
+            lua_pushboolean(L,1);// ->[4] = true
+            lua_setfield(L,-2,name); //represents t[k] = v, [-2 = 3] = t -> v = [4], k = <ClassName>; pop [4]
+        }
+        else
+        {
+            if(IsReferenceCounted<T>())
+                ((Rocket::Core::ReferenceCountable*)obj)->AddReference();
+        }
+        lua_pop(L,1); // -> pop [3]
+    }
+    lua_settop(L,ud); //[ud = 2] -> remove everything that is above 2, top = [2]
+    lua_replace(L, mt); //[mt = 1] -> move [2] to pos [1], and pop previous [1]
+    lua_settop(L, mt); //remove everything above [1]
+    return mt;  // index of userdata containing pointer to T object
+}
+
+
+template<typename T>
+T* LuaType<T>::check(lua_State* L, int narg)
+{
+    T** ptrHold = static_cast<T**>(lua_touserdata(L,narg));
+    if(ptrHold == NULL)
+        return NULL;
+    return (*ptrHold);
+}
+
+
+//private members
+
+template<typename T>
+int LuaType<T>::thunk(lua_State* L)
+{
+    // stack has userdata, followed by method args
+    T *obj = check(L, 1);  // get 'self', or if you prefer, 'this'
+    lua_remove(L, 1);  // remove self so member function args start at index 1
+    // get member function from upvalue
+    RegType *l = static_cast<RegType*>(lua_touserdata(L, lua_upvalueindex(1)));
+    //at the moment, there isn't a case where NULL is acceptable to be used in the function, so check
+    //for it here, rather than individually for each function
+    if(obj == NULL)
+    {
+        lua_pushnil(L);
+        return 1;
+    }
+    else
+        return l->func(L,obj);  // call member function
+}
+
+
+
+template<typename T>
+void LuaType<T>::tostring(char* buff, void* obj)
+{
+    sprintf(buff,"%p",obj);
+}
+
+
+template<typename T>
+int LuaType<T>::gc_T(lua_State* L)
+{
+    T * obj = check(L,1); //[1] = this userdata
+    if(obj == NULL)
+        return 0;
+    lua_getfield(L,LUA_REGISTRYINDEX,"DO NOT TRASH"); //->[2] = return value from this
+    if(lua_istable(L,-1) ) //[-1 = 2], if it is a table
+    {
+        char name[32];
+        tostring(name,obj);
+        lua_getfield(L,-1, std::string(name).c_str()); //[-1 = 2] -> [3] = the value returned from if <ClassName> exists in the table to not gc
+        if(lua_isnil(L,-1) ) //[-1 = 3] if it doesn't exist, then we are free to garbage collect c++ side
+        {
+            if(IsReferenceCounted<T>())
+            {
+                ((Rocket::Core::ReferenceCountable*)obj)->RemoveReference();
+            }
+            else
+            {
+                delete obj;
+                obj = NULL;
+            }
+        }
+    }
+    lua_pop(L,3); //balance function
+    return 0;
+}
+
+
+template<typename T>
+int LuaType<T>::tostring_T(lua_State* L)
+{
+    char buff[32];
+    T** ptrHold = (T**)lua_touserdata(L,1);
+    T *obj = *ptrHold;
+    sprintf(buff, "%p", obj);
+    lua_pushfstring(L, "%s (%s)", GetTClassName<T>(), buff);
+    return 1;
+}
+
+
+
+template<typename T>
+int LuaType<T>::index(lua_State* L)
+{
+    /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
+    lua_getglobal(L,GetTClassName<T>()); //stack pos [3] (fairly important, just refered to as [3])
+    // string form of the key.
+	const char* key = luaL_checkstring(L,2);
+    if(lua_istable(L,-1) )  //[-1 = 3]
+    {
+        lua_pushvalue(L,2); //[2] = key, [4] = copy of key
+        lua_rawget(L,-2); //[-2 = 3] -> pop top and push the return value to top [4]
+        //If the key were looking for is not in the table, retrieve its' metatables' index value.
+        if(lua_isnil(L,-1)) //[-1 = 4] is value from rawget above
+        {
+            //try __getters
+            lua_pop(L,1); //remove top item (nil) from the stack
+            lua_pushstring(L, "__getters");
+            lua_rawget(L,-2); //[-2 = 3], <ClassName>._getters -> result to [4]
+            lua_pushvalue(L,2); //[2 = key] -> copy to [5]
+            lua_rawget(L,-2); //[-2 = __getters] -> __getters[key], result to [5]
+            if(lua_type(L,-1) == LUA_TFUNCTION) //[-1 = 5]
+            {
+                lua_pushvalue(L,1); //push the userdata to the stack [6]
+                if(lua_pcall(L,1,1,0) != 0) //remove one, result is at [6]
+                    Report(L, String(GetTClassName<T>()).Append(".__index for ").Append(lua_tostring(L,2)).Append(": "));
+            }
+            else
+            {
+                lua_settop(L,4); //forget everything we did above
+                lua_getmetatable(L,-2); //[-2 = 3] -> metatable from <ClassName> to top [5]
+                if(lua_istable(L,-1) ) //[-1 = 5] = the result of the above
+                {
+                    lua_getfield(L,-1,"__index"); //[-1 = 5] = check the __index metamethod for the metatable-> push result to [6]
+                    if(lua_isfunction(L,-1) ) //[-1 = 6] = __index metamethod
+                    {
+                        lua_pushvalue(L,1); //[1] = object -> [7] = object
+                        lua_pushvalue(L,2); //[2] = key -> [8] = key
+                        if(lua_pcall(L,2,1,0) != 0) //call function at top of stack (__index) -> pop top 2 as args; [7] = return value
+                            Report(L, String(GetTClassName<T>()).Append(".__index for ").Append(lua_tostring(L,2)).Append(": "));
+                    }
+                    else if(lua_istable(L,-1) )
+                        lua_getfield(L,-1,key); //shorthand version of above -> [7] = return value
+                    else
+                        lua_pushnil(L); //[7] = nil
+                }
+                else
+                    lua_pushnil(L); //[6] = nil
+            }
+        }
+        else if(lua_istable(L,-1) )//[-1 = 4] is value from rawget [3]
+        {
+            lua_pushvalue(L,2); //[2] = key, [5] = key
+            lua_rawget(L,-2); //[-2 = 3] = table of <ClassName> -> pop top and push the return value to top [5]
+        }
+    }
+    else
+        lua_pushnil(L); //[4] = nil
+
+    lua_insert(L,1); //top element to position 1 -> [1] = top element as calculated in the earlier rest of the function
+    lua_settop(L,1); // -> [1 = -1], removes the other elements
+    return 1;
+}
+
+
+
+template<typename T>
+int LuaType<T>::newindex(lua_State* L)
+{
+    //[1] = obj, [2] = key, [3] = value
+    //look for it in __setters
+    lua_getglobal(L,GetTClassName<T>()); //[4] = this table
+    lua_pushstring(L,"__setters"); //[5]
+    lua_rawget(L,-2); //[-2 = 4] -> <ClassName>.__setters to [5]
+    lua_pushvalue(L,2); //[2 = key] -> [6] = copy of key
+    lua_rawget(L,-2); //[-2 = __setters] -> __setters[key] to [6]
+    if(lua_type(L,-1) == LUA_TFUNCTION)
+    {
+        lua_pushvalue(L,1); //userdata at [7]
+        lua_pushvalue(L,3); //[8] = copy of [3]
+        if(lua_pcall(L,2,0,0) != 0) //call function, pop 2 off push 0 on
+            Report(L, String(GetTClassName<T>()).Append(".__newindex for ").Append(lua_tostring(L,2)).Append(": ")); 
+    }
+    else
+        lua_pop(L,1); //not a setter function.
+    lua_pop(L,2); //pop __setters and the <Classname> table
+    return 0;
+}
+
+
+template<typename T>
+void LuaType<T>::_regfunctions(lua_State* L, int meta, int methods)
+{
+    //fill method table with methods.
+    for(RegType* m = (RegType*)GetMethodTable<T>(); m->name; m++)
+    {
+        lua_pushstring(L, m->name); // ->[1] = name of function Lua side
+        lua_pushlightuserdata(L, (void*)m); // ->[2] = pointer to the object containing the name and the function pointer as light userdata
+        lua_pushcclosure(L, thunk, 1); //thunk = function pointer -> pop 1 item from stack, [2] = closure
+        lua_settable(L, methods); // represents t[k] = v, t = [methods] -> pop [2 = closure] to be v, pop [1 = name] to be k
+    }
+
+    
+    lua_getfield(L,methods, "__getters"); // -> table[1]
+    if(lua_isnoneornil(L,-1))
+    {
+        lua_pop(L,1); //pop unsuccessful get
+        lua_newtable(L); // -> table [1]
+        lua_setfield(L,methods,"__getters"); // pop [1]
+        lua_getfield(L,methods,"__getters"); // -> table [1]
+    }
+    for(luaL_Reg* m = (luaL_Reg*)GetAttrTable<T>(); m->name; m++)
+    {
+        lua_pushcfunction(L,m->func); // -> [2] is this function
+        lua_setfield(L,-2,m->name); //[-2 = 1] -> __getters.name = function
+    }
+    lua_pop(L,1); //pop __getters
+
+
+    lua_getfield(L,methods, "__setters"); // -> table[1]
+    if(lua_isnoneornil(L,-1))
+    {
+        lua_pop(L,1); //pop unsuccessful get
+        lua_newtable(L); // -> table [1]
+        lua_setfield(L,methods,"__setters"); // pop [1]
+        lua_getfield(L,methods,"__setters"); // -> table [1]
+    }
+    for(luaL_Reg* m = (luaL_Reg*)SetAttrTable<T>(); m->name; m++)
+    {
+        lua_pushcfunction(L,m->func); // -> [2] is this function
+        lua_setfield(L,-2,m->name); //[-2 = 1] -> __setters.name = function
+    }
+    lua_pop(L,1); //pop __setters
+}
+
+}
+}
+}

+ 83 - 0
Include/Rocket/Core/Lua/Utilities.h

@@ -0,0 +1,83 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCORELUAUTILITIES_H
+#define ROCKETCORELUAUTILITIES_H
+/*
+    This file is for free-floating functions that are used across more than one file.
+*/
+#include <Rocket/Core/Lua/Header.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Variant.h>
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+/** casts the variant to its specific type before pushing it to the stack 
+@relates Rocket::Core::Lua::LuaType */
+void ROCKETLUA_API PushVariant(lua_State* L, Variant* var);
+
+/** If there are errors on the top of the stack, this will print those out to the log.
+@param L A Lua state, and if not passed in, will use the Interpreter's state
+@param place A string that will be printed to the log right before the error message, seperated by a space. Set
+this when you would get no information about where the error happens.
+@relates Rocket::Core::Lua::Interpreter   */
+void ROCKETLUA_API Report(lua_State* L = NULL, const Rocket::Core::String& place = "");
+
+//Helper function, so that the types don't have to define individual functions themselves
+// to fill the Elements.As table
+template<typename ToType>
+int CastFromElementTo(lua_State* L)
+{
+    Element* ele = LuaType<Element>::check(L,1);
+    LUACHECKOBJ(ele);
+    LuaType<ToType>::push(L,(ToType*)ele,false);
+    return 1;
+}
+
+//Adds to the Element.As table the name of the type, and the function to use to cast
+template<typename T>
+void AddTypeToElementAsTable(lua_State* L)
+{
+    int top = lua_gettop(L);
+    lua_getglobal(L,"Element");
+    lua_getfield(L,-1,"As");
+    if(!lua_isnoneornil(L,-1))
+    {
+        lua_pushcfunction(L,CastFromElementTo<T>);
+        lua_setfield(L,-2,GetTClassName<T>());
+    }
+    lua_settop(L,top); //pop "As" and "Element"
+}
+}
+}
+}
+
+
+#endif

+ 34 - 0
Include/Rocket/Core/Lua/lua.hpp

@@ -0,0 +1,34 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+//The standard Lua headers
+
+extern "C" {
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+}

+ 35 - 0
Samples/luainvaders/data/background.rml

@@ -0,0 +1,35 @@
+<rml>
+	<head>
+		<style>
+			body
+			{
+				width: 100%;
+				height: 100%;
+				z-index: bottom;
+
+				z-index: -1;
+			}
+
+			starfield
+			{
+				display: block;
+				width: 100%;
+				height: 100%;
+				z-index: 1;
+
+				star-decorator: starfield;
+				star-num-layers: 5;
+				star-top-colour: #fffc;
+				star-bottom-colour: #fff3;
+				star-top-speed: 80.0;
+				star-bottom-speed: 20.0;
+				star-top-density: 8;
+				star-bottom-density: 20;
+			}
+		</style>
+	</head>
+	<body>
+		<img src="background.tga" />
+		<starfield />
+	</body>
+</rml>

BIN
Samples/luainvaders/data/background.tga


+ 126 - 0
Samples/luainvaders/data/game.rml

@@ -0,0 +1,126 @@
+<rml>
+	<head>
+		<title>game</title>
+		<link type="text/template" href="window.rml" />
+		<style>
+			body
+			{
+				padding: 0px;
+				margin: 0px;
+				width: 100%;
+				height: 100%;
+
+				z-index: -1;
+			}
+			
+			game
+			{
+				display: block;
+				width: 100%;
+				height: 100%;
+			}
+
+			div
+			{
+				height: 47px;
+				padding: 9px 0px 0px 65px;
+				margin: 0px 20px;
+
+				font-size: 20;
+
+				background-decorator: tiled-horizontal;
+				background-left-image: ../../assets/invader.tga 147px 55px 229px 0px;
+				background-center-image: ../../assets/invader.tga stretch 229px 55px 230px 0px;
+				background-right-image: ../../assets/invader.tga 231px 55px 246px 0px;
+			}
+
+			div#score_div
+			{
+				float: left;
+				width: 155px;
+			}
+
+			div#hiscore_div
+			{
+				float: left;
+				width: 205px;
+			}
+
+			div#waves_div
+			{
+				float: right;
+				width: 95px;
+			}
+
+			div#lives_div
+			{
+				float: right;
+				width: 80px;
+			}
+
+			icon
+			{
+				display: block;
+				position: absolute;
+				left: 14px;
+				top: 3px;
+
+				width: 51px;
+				height: 39px;
+				
+				icon-decorator: image;
+				icon-image-src: ../../assets/invader.tga;
+				icon-image-t: 152px 191px;
+			}
+
+			div#score_div icon
+			{
+				icon-image-s: 434px 485px;
+			}
+
+			div#hiscore_div icon
+			{
+				icon-image-s: 281px 332px;
+			}
+
+			div#waves_div icon
+			{
+				icon-image-s: 332px 383px;
+			}
+
+			div#lives_div icon
+			{
+				icon-image-s: 383px 434px;
+			}
+		</style>
+		<script>
+Game = Game or {} --namespace for functions
+
+function Game.OnKeyDown(event, document)
+	if event.parameters['key_identifier'] == rocket.key_identifier.ESCAPE then
+		document.context:LoadDocument('data/pause.rml'):Show()
+    end
+end
+		</script>
+	</head>
+	<body id="game_window" onkeydown="Game.OnKeyDown(event, document)" ongameover="Window.LoadMenu('high_score',document)">
+		<game id="game">
+			<div id="score_div">
+				<icon />
+				score: <span id="score" />
+			</div>
+			<div id="hiscore_div">
+				<icon />
+				high score: <span id="hiscore" />
+			</div>
+			<div id="lives_div">
+				<icon />
+				lives: <span id="lives" />
+			</div>
+			<div id="waves_div">
+				<icon />
+				wave: <span id="waves" />
+			</div>
+		</game>
+	</body>
+</rml>

+ 55 - 0
Samples/luainvaders/data/help.rml

@@ -0,0 +1,55 @@
+<rml>
+	<head>
+		<title>Help</title>
+		<link type="text/template" href="window.rml" />
+		<style>
+			body
+			{
+				width: 50%;
+				height: 70%;
+				margin: auto;
+			}
+			
+			div#content
+			{
+				overflow-y: scroll;
+			}
+			
+			div#title_bar div#icon
+			{
+				icon-image-s: 128px 179px;
+				icon-image-t: 152px 191px;
+			}
+		</style>
+	</head>
+	<body template="luawindow">
+		<h1>Story</h1>
+		<p>
+			One day, without warning, they came for us; endless waves of the invaders, numbers too vast to count, fresh from the Martian foundries. Earth's orbital defences took a heavy toll, but were inevitably overrun, buying enough time only for a single rocket ship to launch. The prototype X-42 'Defender'-class, not yet tested but piloted by the finest astronaut the Space Corps had to offer.
+		</p>
+		<p>
+			Do you have what it takes to defeat the invaders and save Earth?
+		</p>
+		<h1>The X-42</h1>
+		<p>
+			The culmination of <img src="help_defender.tga" style="float: left; margin: -6px -24px;" />decades of research and the pinnacle of Earth's technology, the X-42 'Defender' is the finest weapon mankind has to fight the alien menace. Equipped with the dual-layer ablative tridranium armour, low-velocity depleted-narconium chain-fed belt gun and state-of-the-art liquid-hydrangea turbo-thrusters, it is still going to be nearly impossible for its pilot to secure the safety of mankind.
+		</p>
+		<h1>The Invaders</h1>
+		<p>
+			The most numerous <img src="help_invader_rank1.tga" style="float: left; margin: -4px 0px;" />invader you'll face is a primitive drone that is primarily employed by its Martian overlords in the mines of Cydonia. It is large, ungainly and poorly-armed, so ill-suited to its new role as the backbone of the invasion fleet. However, whatever it lacks in pugilistic prowess it makes up for with numbers. Each drone is worth 10 points.
+		</p>
+		<p>
+			Behind the drones <img src="help_invader_rank2.tga" style="float: right; margin: -4px 0px;" />stand the formidable berserker units, encased in their zyterium battle-suits and wielding the dreaded Nimbus death-rods. A lone unit is no match for a skilled X-42 pilot, but in large groups they adopt complex flight patterns that can confuse even the best targetting computer. Pick them off and separate them when you can. Each berserker is worth 20 points.
+		</p>
+		<p>
+			The dreaded commander <img src="help_invader_rank3.tga" style="float: left; margin: -4px 0px;" />death-droids lie at the back of every Martian wave. Small, nimble and deadly, these ships are the true test of an X-42 pilot's abilities. Consider yourself warned, and watch out especially for their mind control attack! Each droid is worth 40 points.
+		</p>
+		<p>
+			Occasionally one of the <img src="help_invader_mothership.tga" style="float: right; margin: -6px -12px;" /> invasion motherships will drop into low-orbit to provide the Martian Overbrain with a close look at the progress of the battle; this is when they are most vulnerable, destroy them if you can! The loss of even a single mothership will be keenly felt by the fleet. The points value of each mothership is variable, depending on the seniority of its command synapse.
+		</p>
+		<p>
+			Destroy all the invaders in each wave before any get past your ship to invade Earth, unleash their deadly toxin and wipe out all of humanity!
+		</p>
+		<button onclick="Window.LoadMenu('main_menu',document)">Back</button>
+	</body>
+</rml>

BIN
Samples/luainvaders/data/help_defender.tga


BIN
Samples/luainvaders/data/help_invader_mothership.tga


BIN
Samples/luainvaders/data/help_invader_rank1.tga


BIN
Samples/luainvaders/data/help_invader_rank2.tga


BIN
Samples/luainvaders/data/help_invader_rank3.tga


+ 76 - 0
Samples/luainvaders/data/high_score.rml

@@ -0,0 +1,76 @@
+<rml>
+	<head>
+		<title>High Scores</title>
+		<link type="text/template" href="window.rml" />
+		<style>
+			body
+			{
+				width: 350px;
+				height: 350px;
+				
+				margin: auto;
+			}
+			
+			div#title_bar div#icon
+			{
+				icon-image-s: 281px 331px;
+				icon-image-t: 152px 191px;
+			}
+			
+			datagrid
+			{
+				margin-bottom: 20px;
+				min-rows: 10;
+			}
+			
+			datagrid data_grid_body
+			{
+				min-height: 200px;
+			}
+			
+			defender
+			{
+				display: block;
+				width: 64px;
+				height: 16px;
+				
+				defender-decorator: defender;
+				defender-image-src: high_scores_defender.tga;
+			}
+		</style>
+		<script>
+HighScore = HighScore or {}
+
+--because we pass it as a plain function in HighScore.OnLoad, we have to pay attention
+--to the order of arguments. We don't need the first two in this case, so the name doesn't matter
+function HighScore.OnRowAdd(_,_,document)
+	input = document:GetElementById('player_input')
+	if input then
+		input:Focus()
+    end
+end
+
+function HighScore.OnLoad(window)
+	Window.OnWindowLoad(window)
+	local datagrid = window:GetElementById('datagrid')
+	datagrid:AddEventListener('rowupdate', HighScore.OnRowAdd, false)
+end
+	
+function HighScore.OnKeyDown(event)
+	if event.parameters['key_identifier'] == rocket.key_identifier.RETURN then
+        Game.SetHighScoreName(Element.As.ElementFormControlInput(event.current_element).value)
+		--Game.SetHighScoreName(event.current_element:AsType(Element.etype.input).value)
+    end
+end
+		</script>
+	</head>
+	<body template="luawindow" onload="HighScore.OnLoad(document) Game.SubmitHighScore()" onunload="Game.SetHighScoreName('Anon')">
+		<datagrid id="datagrid" source="high_scores.scores">
+			<col fields="name,name_required" formatter="name" width="40%">Pilot:</col>
+			<col fields="colour" formatter="ship" width="20%">Ship:</col>
+			<col fields="wave" width="20%">Wave:</col>
+			<col fields="score" width="20%">Score:</col>
+		</datagrid>
+		<button onclick="Window.LoadMenu('main_menu',document)">Main Menu</button>
+	</body>
+</rml>

BIN
Samples/luainvaders/data/high_scores_defender.tga


BIN
Samples/luainvaders/data/invaders.tga


+ 23 - 0
Samples/luainvaders/data/logo.rml

@@ -0,0 +1,23 @@
+<rml>
+	<head>
+		<style>
+			body
+			{
+				width: 100%;
+				height: 100%;
+
+				z-index: -1;
+			}
+			
+			#rifm_logo
+			{
+				position: absolute;
+				left: 25px;
+				top: 25px;
+			}
+		</style>
+	</head>
+	<body id="logo">
+		<img id="rifm_logo" src="logo.tga" />
+	</body>
+</rml>

BIN
Samples/luainvaders/data/logo.tga


+ 38 - 0
Samples/luainvaders/data/main_menu.rml

@@ -0,0 +1,38 @@
+<rml>
+	<head>
+		<title>Main Menu</title>
+		<link type="text/template" href="window.rml" />
+		<style>
+			body
+			{
+				width: 300px;
+				height: 225px;
+
+				margin: auto;
+			}
+			
+			div#title_bar div#icon
+			{
+				icon-image-s: 179px 230px;
+				icon-image-t: 152px 191px;
+			}
+		</style>
+		<script>
+MainMenu = MainMenu or {}
+
+function MainMenu.CloseLogo(document)
+	if document.context then
+        local logo = document.context.documents['logo']
+        if logo then logo:Close() end
+    end
+end
+		</script>
+	</head>
+	<body template="luawindow" onload="Window.OnWindowLoad(document) document.context:LoadDocument('data/logo.rml'):Show()" onunload="MainMenu.CloseLogo(document)">
+		<button onclick="document.context:LoadDocument('data/start_game.rml'):Show() document:Close()">Start Game</button><br />
+		<button onclick="Window.LoadMenu('high_score',document)">High Scores</button><br />
+		<button onclick="Window.LoadMenu('options',document)">Options</button><br />
+		<button onclick="Window.LoadMenu('help',document)">Help</button><br />
+		<button onclick="Game.Shutdown()">Exit</button>
+	</body>
+</rml>

+ 119 - 0
Samples/luainvaders/data/options.rml

@@ -0,0 +1,119 @@
+<rml>
+	<head>
+		<title>Options</title>
+		<link type="text/template" href="window.rml" />
+		<style>
+			body
+			{
+				width: 350px;
+				height: 350px;
+				
+				margin: auto;
+			}
+
+			div#title_bar div#icon
+			{
+				icon-image-s: 230px 281px;
+				icon-image-t: 152px 191px;
+
+				display: none;
+			}
+
+			form div
+			{
+				width: 200px;
+				margin: auto;
+			}
+		</style>
+		<script>
+Options = Options or {}
+
+function Options.Serialize(filename,options)
+    local file,message = io.open(filename,'w+') --w+ will erase the previous data
+    if file == nil then Log.Message(Log.logtype.error, "Error saving options in options.rml: " .. message) return end
+    --cache the function
+    local format = string.format
+    
+    for key,value in pairs(options) do
+        file:write(tostring(key)..'='..tostring(value)..'\n')
+    end
+    file:close()
+end
+
+function Options.Deserialize(filename)
+    local ret = {} --table to return
+    --cache functions that are used a lot for faster lookup
+    local gmatch = string.gmatch
+    
+    local f = io.open(filename)
+    if f then
+        for line in f:lines() do
+            for k,v in gmatch(line, '(%w+)=(%w+)') do ret[k] = v end
+        end 
+        f:close()
+    else
+        return nil
+    end
+    
+    return ret
+end
+        
+        
+function Options.LoadOptions(document)
+    local options = Options.Deserialize('options.dat')
+    if options == nil then return end --short circuit if the file doesn't exist
+    local AsInput = Element.As.ElementFormControlInput
+    
+    AsInput(document:GetElementById(options['graphics'])).checked = true
+    --because everything is loaded as a string, we have to fool around with the boolean variables
+    AsInput(document:GetElementById('reverb')).checked = (options['reverb'] == 'true')
+    AsInput(document:GetElementById('3d')).checked = (options['3d'] == 'true')
+end
+
+function Options.SaveOptions(event)
+    if event.parameters['button'] == 'cancel' then
+        return
+    end
+		
+    local options = {}
+    local params = event.parameters
+    options['graphics'] = params['graphics']
+    --because of how checkboxes won't be in the event params if they aren't checked,
+    --we return false if they don't exist. This is Lua's ternary operator.
+    options['reverb'] = params['reverb'] and true or false
+    options['3d'] = params['3d'] and true or false
+    
+    Options.Serialize('options.dat',options)
+end
+		
+function Options.DisplayBadGraphics(document, display)
+	if display then
+		document:GetElementById('bad_warning').style.display = 'block'
+	else
+		document:GetElementById('bad_warning').style.display = 'none'
+    end
+end
+
+	</script>
+	</head>
+	<body template="luawindow" onload="Window.OnWindowLoad(document) Options.LoadOptions(document)">
+		<form onsubmit="Options.SaveOptions(event) Window.LoadMenu('main_menu',document)">
+			<div>
+				<p>
+					Graphics:<br />
+					<input id="good" type="radio" name="graphics" value="good"/> Good<br />
+					<input id="ok" type="radio" name="graphics" value="ok" checked="true"/> OK<br />
+					<input id="bad" type="radio" name="graphics" value="bad" onchange="Options.DisplayBadGraphics(document, true)" /> Bad<br />
+				</p>
+				<p id="bad_warning" style="display: none;">Are you sure about this? Bad graphics are just plain <em>bad.</em></p>
+				<p>
+					Audio:<br />
+					<input id="reverb" type="checkbox" name="reverb" value="true" checked="true" /> Reverb<br />
+					<input id="3d" type="checkbox" name="3d" value="false" checked="false" /> 3D Spatialisation
+				</p>
+			</div>
+			<input type="submit" name="button" value="accept">Accept</input>
+			<input type="submit" name="button" value="cancel">Cancel</input>
+		</form>
+	</body>
+</rml>

+ 27 - 0
Samples/luainvaders/data/pause.rml

@@ -0,0 +1,27 @@
+<rml>
+	<head>
+		<title>Quit?</title>
+		<link type="text/template" href="window.rml" />
+		<style>
+			body
+			{
+				width: 350px;
+				height: 135px;
+				
+				margin: auto;
+			}
+			
+			div#title_bar div#icon
+			{
+				icon-image-s: 332px 383px;
+				icon-image-t: 191px 231px;
+			}
+		</style>
+	</head>
+	<body template="luawindow" onload="Window.OnWindowLoad(document) Game.SetPaused(true)" onunload="Game.SetPaused(false)">
+		<br />
+		<p>Are you sure you want to end this game?</p>
+		<button onclick="Window.LoadMenu('high_score',document) document.context.documents['game_window']:Close()">Yes</button>
+		<button onclick="document:Close()">No!</button>
+	</body>
+</rml>

+ 71 - 0
Samples/luainvaders/data/start_game.rml

@@ -0,0 +1,71 @@
+<rml>
+	<head>
+		<title>Start Game</title>
+		<link type="text/template" href="window.rml" />
+		<style>
+			body
+			{
+				width: 300px;
+				height: 225px;
+				
+				margin: auto;
+			}
+			
+			div#title_bar div#icon
+			{
+				icon-image-s: 230px 281px;
+				icon-image-t: 152px 191px;
+			}
+			
+			form div
+			{
+				width: 200px;
+				margin: auto;
+			}
+		</style>
+		<script>
+StartGame = StartGame or {}
+
+function StartGame.SetupGame(event,document)
+	if event.parameters['difficulty'] == 'hard' then
+		Game.SetDifficulty(Game.difficulty.HARD)
+	else
+		Game.SetDifficulty(Game.difficulty.EASY)
+    end
+	
+    --some lua trickery coming up. Compiling a string at runtime that will return the values,
+    --because they are comma separated. For example, if the user chose "Denim", then the
+    --compiled string would look like "return 21,96,189"
+    local red,green,blue = loadstring('return '..event.parameters['colour']) ()
+	Game.SetDefenderColour(Colourb.new(red,green,blue,255))
+	
+	local elem = Window.LoadMenu('game',document):GetElementById('game')
+	elem:Focus()
+end
+		</script>
+	</head>
+	<body template="luawindow">
+		<form onsubmit="StartGame.SetupGame(event,document)">
+			<div>
+				<p>
+					Difficulty:<br />
+					<input type="radio" name="difficulty" value="easy" checked="true" /> Easy<br />
+					<input type="radio" name="difficulty" value="hard" /> Hard
+				</p>
+				<p>
+					Colour:<br />
+					<select name="colour">
+						<option value="233,116,81">Burnt Sienna</option>
+						<option value="127,255,0">Chartreuse</option>
+						<option value="21,96,189">Denim</option>
+						<option value="246,74,138">French Rose</option>
+						<option value="255,0,255">Fuschia</option>
+						<option value="218,165,32">Goldenrod</option>
+						<option selected value="255,255,240">Ivory</option>
+					</select>
+				</p>
+			</div>
+			<input type="submit">Start Game!</input>
+		</form>
+	</body>
+</rml>

+ 24 - 0
Samples/luainvaders/data/window.rml

@@ -0,0 +1,24 @@
+<template name="luawindow" content="content">
+<head>
+	<link type="text/template" href="../../assets/window.rml" />
+	<script>
+Window = Window or {} --namespace
+
+function Window.OnWindowLoad(document)
+	document:GetElementById('title').inner_rml = document.title
+end
+	
+function Window.LoadMenu(name,document)
+	local doc = document.context:LoadDocument('data/' .. name .. '.rml')
+	if doc then
+		doc:Show()
+		document:Close()
+    end
+	
+	return doc
+end
+	</script>
+</head>
+<body template="window" onload="Window.OnWindowLoad(document)">
+</body>
+</template>

+ 40 - 0
Samples/luainvaders/lua/start.lua

@@ -0,0 +1,40 @@
+
+Formatters = Formatters or {} --table to hold the formatters so that they don't get GC'd
+
+--this will use two different ways to show how to create DataFormatter objects
+--first way is to set the FormatData function explicitly
+local formatter = DataFormatter.new("name")
+formatter.FormatData = function(raw_data)
+    --[[ 
+    Data format:
+    raw_data[0] is the name.
+    raw_data[1] is a bool - True means the name has to be entered. False means the name has been entered already.
+    ]]
+    
+    formatted_data = ""
+    
+    if (raw_data[1] == "1") then
+        --because we know that it is only used in the high_score.rml file, use that namespace for the OnKeyDown function
+        formatted_data = "<input id=\"player_input\" type=\"text\" name=\"name\" onkeydown=\"HighScore.OnKeyDown(event)\" />"
+    else
+        formatted_data = raw_data[0]
+    end
+        
+    return formatted_data
+end
+Formatters["name"] = formatter --using "name" as the key only for convenience
+
+--second example uses a previously defined function, and passes in as a parameter for 'new'
+function SecondFormatData(raw_data)
+    return "<defender style=\"color: rgba(" .. raw_data[0] .. ");\" />"
+end
+Formatters["ship"] = DataFormatter.new("ship",SecondFormatData)
+
+
+function Startup()
+	maincontext = rocket.contexts["main"]
+	maincontext:LoadDocument("data/background.rml"):Show()
+	maincontext:LoadDocument("data/main_menu.rml"):Show()
+end
+
+Startup()

+ 86 - 0
Samples/luainvaders/src/DecoratorDefender.cpp

@@ -0,0 +1,86 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "DecoratorDefender.h"
+#include <Rocket/Core/Element.h>
+#include <Rocket/Core/Texture.h>
+#include <Rocket/Core/Math.h>
+#include <ShellOpenGL.h>
+
+DecoratorDefender::~DecoratorDefender()
+{
+}
+
+bool DecoratorDefender::Initialise(const Rocket::Core::String& image_source, const Rocket::Core::String& image_path)
+{
+	image_index = LoadTexture(image_source, image_path);
+	if (image_index == -1)
+	{
+		return false;
+	}
+
+	return true;
+}
+
+/// Called on a decorator to generate any required per-element data for a newly decorated element.
+Rocket::Core::DecoratorDataHandle DecoratorDefender::GenerateElementData(Rocket::Core::Element* ROCKET_UNUSED(element))
+{
+	return NULL;
+}
+
+// Called to release element data generated by this decorator.
+void DecoratorDefender::ReleaseElementData(Rocket::Core::DecoratorDataHandle ROCKET_UNUSED(element_data))
+{
+}
+
+// Called to render the decorator on an element.
+void DecoratorDefender::RenderElement(Rocket::Core::Element* element, Rocket::Core::DecoratorDataHandle ROCKET_UNUSED(element_data))
+{
+	Rocket::Core::Vector2f position = element->GetAbsoluteOffset(Rocket::Core::Box::PADDING);
+	Rocket::Core::Vector2f size = element->GetBox().GetSize(Rocket::Core::Box::PADDING);
+
+	glEnable(GL_TEXTURE_2D);
+	glBindTexture(GL_TEXTURE_2D, (GLuint) GetTexture(image_index)->GetHandle(element->GetRenderInterface()));
+	Rocket::Core::Colourb colour = element->GetProperty< Rocket::Core::Colourb >("color");
+	glColor4ubv(element->GetProperty< Rocket::Core::Colourb >("color"));
+	glBegin(GL_QUADS);
+
+		glVertex2f(position.x, position.y);
+		glTexCoord2f(0, 1);
+
+		glVertex2f(position.x, position.y + size.y);
+		glTexCoord2f(1, 1);
+
+		glVertex2f(position.x + size.x, position.y + size.y);
+		glTexCoord2f(1, 0);
+
+		glVertex2f(position.x + size.x, position.y);
+		glTexCoord2f(0, 0);
+
+	glEnd();
+	glColor4ub(255, 255, 255, 255);
+}

+ 57 - 0
Samples/luainvaders/src/DecoratorDefender.h

@@ -0,0 +1,57 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSDECORATORDEFENDER_H
+#define ROCKETINVADERSDECORATORDEFENDER_H
+
+#include <Rocket/Core/Decorator.h>
+
+class DecoratorDefender : public Rocket::Core::Decorator
+{
+public:
+	virtual ~DecoratorDefender();
+
+	bool Initialise(const Rocket::Core::String& image_source, const Rocket::Core::String& image_path);
+
+	/// Called on a decorator to generate any required per-element data for a newly decorated element.
+	/// @param element[in] The newly decorated element.
+	/// @return A handle to a decorator-defined data handle, or NULL if none is needed for the element.
+	virtual Rocket::Core::DecoratorDataHandle GenerateElementData(Rocket::Core::Element* element);
+	/// Called to release element data generated by this decorator.
+	/// @param element_data[in] The element data handle to release.
+	virtual void ReleaseElementData(Rocket::Core::DecoratorDataHandle element_data);
+
+	/// Called to render the decorator on an element.
+	/// @param element[in] The element to render the decorator on.
+	/// @param element_data[in] The handle to the data generated by the decorator for the element.
+	virtual void RenderElement(Rocket::Core::Element* element, Rocket::Core::DecoratorDataHandle element_data);
+
+private:
+	int image_index;
+};
+
+#endif

+ 67 - 0
Samples/luainvaders/src/DecoratorInstancerDefender.cpp

@@ -0,0 +1,67 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "DecoratorInstancerDefender.h"
+#include <Rocket/Core/Math.h>
+#include <Rocket/Core/String.h>
+#include "DecoratorDefender.h"
+
+DecoratorInstancerDefender::DecoratorInstancerDefender()
+{
+	RegisterProperty("image-src", "").AddParser("string");
+}
+
+DecoratorInstancerDefender::~DecoratorInstancerDefender()
+{
+}
+
+// Instances a decorator given the property tag and attributes from the RCSS file.
+Rocket::Core::Decorator* DecoratorInstancerDefender::InstanceDecorator(const Rocket::Core::String& ROCKET_UNUSED(name), const Rocket::Core::PropertyDictionary& properties)
+{
+	const Rocket::Core::Property* image_source_property = properties.GetProperty("image-src");
+	Rocket::Core::String image_source = image_source_property->Get< Rocket::Core::String >();
+
+	DecoratorDefender* decorator = new DecoratorDefender();
+	if (decorator->Initialise(image_source, image_source_property->source))
+		return decorator;
+
+	decorator->RemoveReference();
+	ReleaseDecorator(decorator);
+	return NULL;
+}
+
+// Releases the given decorator.
+void DecoratorInstancerDefender::ReleaseDecorator(Rocket::Core::Decorator* decorator)
+{
+	delete decorator;
+}
+
+// Releases the instancer.
+void DecoratorInstancerDefender::Release()
+{
+	delete this;
+}

+ 56 - 0
Samples/luainvaders/src/DecoratorInstancerDefender.h

@@ -0,0 +1,56 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSDECORATORINSTANCERDEFENDER_H
+#define ROCKETINVADERSDECORATORINSTANCERDEFENDER_H
+
+#include <Rocket/Core/DecoratorInstancer.h>
+
+/**
+	@author Robert Curry
+ */
+
+class DecoratorInstancerDefender : public Rocket::Core::DecoratorInstancer
+{
+public:
+	DecoratorInstancerDefender();
+	virtual ~DecoratorInstancerDefender();
+
+	/// Instances a decorator given the property tag and attributes from the RCSS file.
+	/// @param[in] name The type of decorator desired. For example, "background-decorator: simple;" is declared as type "simple".
+	/// @param[in] properties All RCSS properties associated with the decorator.
+	/// @return The decorator if it was instanced successful, NULL if an error occured.
+	Rocket::Core::Decorator* InstanceDecorator(const Rocket::Core::String& name, const Rocket::Core::PropertyDictionary& properties);
+	/// Releases the given decorator.
+	/// @param[in] decorator Decorator to release. This is guaranteed to have been constructed by this instancer.
+	void ReleaseDecorator(Rocket::Core::Decorator* decorator);
+
+	/// Releases the instancer.
+	void Release();
+};
+
+#endif

+ 78 - 0
Samples/luainvaders/src/DecoratorInstancerStarfield.cpp

@@ -0,0 +1,78 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "DecoratorStarfield.h"
+#include <Rocket/Core/Math.h>
+#include <Rocket/Core/Types.h>
+#include "DecoratorInstancerStarfield.h"
+
+DecoratorInstancerStarfield::DecoratorInstancerStarfield()
+{
+	RegisterProperty("num-layers", "3").AddParser("number");
+	RegisterProperty("top-colour", "#dddc").AddParser("color");
+	RegisterProperty("bottom-colour", "#333c").AddParser("color");
+	RegisterProperty("top-speed", "10.0").AddParser("number");
+	RegisterProperty("bottom-speed", "2.0").AddParser("number");
+	RegisterProperty("top-density", "15").AddParser("number");
+	RegisterProperty("bottom-density", "10").AddParser("number");
+}
+
+DecoratorInstancerStarfield::~DecoratorInstancerStarfield()
+{
+}
+
+// Instances a decorator given the property tag and attributes from the RCSS file.
+Rocket::Core::Decorator* DecoratorInstancerStarfield::InstanceDecorator(const Rocket::Core::String& ROCKET_UNUSED(name), const Rocket::Core::PropertyDictionary& properties)
+{
+	int num_layers = Rocket::Core::Math::RealToInteger(properties.GetProperty("num-layers")->Get< float >());
+	Rocket::Core::Colourb top_colour = properties.GetProperty("top-colour")->Get< Rocket::Core::Colourb >();
+	Rocket::Core::Colourb bottom_colour = properties.GetProperty("bottom-colour")->Get< Rocket::Core::Colourb >();
+	float top_speed = properties.GetProperty("top-speed")->Get< float >();
+	float bottom_speed = properties.GetProperty("bottom-speed")->Get< float >();
+	int top_density = Rocket::Core::Math::RealToInteger(properties.GetProperty("top-density")->Get< float >());
+	int bottom_density = Rocket::Core::Math::RealToInteger(properties.GetProperty("bottom-density")->Get< float >());
+
+	DecoratorStarfield* decorator = new DecoratorStarfield();
+	if (decorator->Initialise(num_layers, top_colour, bottom_colour, top_speed, bottom_speed, top_density, bottom_density))
+		return decorator;
+
+	decorator->RemoveReference();
+	ReleaseDecorator(decorator);
+	return NULL;
+}
+
+// Releases the given decorator.
+void DecoratorInstancerStarfield::ReleaseDecorator(Rocket::Core::Decorator* decorator)
+{
+	delete decorator;
+}
+
+// Releases the instancer.
+void DecoratorInstancerStarfield::Release()
+{
+	delete this;
+}

+ 57 - 0
Samples/luainvaders/src/DecoratorInstancerStarfield.h

@@ -0,0 +1,57 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSDECORATORINSTANCERSTARFIELD_H
+#define ROCKETINVADERSDECORATORINSTANCERSTARFIELD_H
+
+#include <Rocket/Core/DecoratorInstancer.h>
+#include "DecoratorStarfield.h"
+
+/**
+	@author Robert Curry
+ */
+
+class DecoratorInstancerStarfield : public Rocket::Core::DecoratorInstancer
+{
+public:
+	DecoratorInstancerStarfield();
+	virtual ~DecoratorInstancerStarfield();
+
+	/// Instances a decorator given the property tag and attributes from the RCSS file.
+	/// @param name The type of decorator desired. For example, "background-decorator: simple;" is declared as type "simple".
+	/// @param properties All RCSS properties associated with the decorator.
+	/// @return The decorator if it was instanced successful, NULL if an error occured.
+	Rocket::Core::Decorator* InstanceDecorator(const Rocket::Core::String& name, const Rocket::Core::PropertyDictionary& properties);
+	/// Releases the given decorator.
+	/// @param decorator Decorator to release. This is guaranteed to have been constructed by this instancer.
+	void ReleaseDecorator(Rocket::Core::Decorator* decorator);
+
+	/// Releases the instancer.
+	void Release();
+};
+
+#endif

+ 145 - 0
Samples/luainvaders/src/DecoratorStarfield.cpp

@@ -0,0 +1,145 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "DecoratorStarfield.h"
+#include <Rocket/Core/Math.h>
+#include <Rocket/Core/Element.h>
+#include <Shell.h>
+#include <ShellOpenGL.h>
+#include "GameDetails.h"
+
+float last_update_time = 0.0f;
+
+DecoratorStarfield::~DecoratorStarfield()
+{
+}
+
+bool DecoratorStarfield::Initialise(int _num_layers, const Rocket::Core::Colourb& _top_colour, const Rocket::Core::Colourb& _bottom_colour, float _top_speed, float _bottom_speed, int _top_density, int _bottom_density)
+{
+	num_layers = _num_layers;
+	top_colour = _top_colour;
+	bottom_colour = _bottom_colour;
+	top_speed = _top_speed;
+	bottom_speed = _bottom_speed;
+	top_density = _top_density;
+	bottom_density = _bottom_density;
+
+	return true;
+}
+
+/// Called on a decorator to generate any required per-element data for a newly decorated element.
+Rocket::Core::DecoratorDataHandle DecoratorStarfield::GenerateElementData(Rocket::Core::Element* element)
+{
+	StarField* star_field = new StarField();
+
+	star_field->star_layers.resize(num_layers);
+
+	for (int i = 0; i < num_layers; i++)
+	{
+		float layer_depth = i / (float)num_layers;
+
+		int density = Rocket::Core::Math::RealToInteger((top_density * layer_depth) + (bottom_density * (1.0f - layer_depth)));
+		star_field->star_layers[i].stars.resize(density);
+
+		Rocket::Core::Colourb colour = (top_colour * layer_depth) + (bottom_colour * (1.0f - layer_depth));
+		star_field->star_layers[i].colour = colour;
+
+		float speed = (top_speed * layer_depth) + (bottom_speed * (1.0f - layer_depth));
+		star_field->star_layers[i].speed = speed;
+
+		star_field->dimensions = element->GetBox().GetSize(Rocket::Core::Box::PADDING);
+
+		if (star_field->dimensions.x > 0)
+		{
+			for (int j = 0; j < density; j++)
+			{
+				star_field->star_layers[i].stars[j].x = (float) Rocket::Core::Math::RandomReal(star_field->dimensions.x);
+				star_field->star_layers[i].stars[j].y = (float) Rocket::Core::Math::RandomReal(star_field->dimensions.y);
+			}
+		}
+
+		star_field->last_update = Shell::GetElapsedTime();
+	}
+
+	return (Rocket::Core::DecoratorDataHandle)star_field;
+}
+
+// Called to release element data generated by this decorator.
+void DecoratorStarfield::ReleaseElementData(Rocket::Core::DecoratorDataHandle element_data)
+{
+	delete (StarField*)element_data;
+}
+
+// Called to render the decorator on an element.
+void DecoratorStarfield::RenderElement(Rocket::Core::Element* ROCKET_UNUSED(element), Rocket::Core::DecoratorDataHandle element_data)
+{
+	StarField* star_field = (StarField*)element_data;
+	star_field->Update();
+
+	glDisable(GL_TEXTURE_2D);
+	glPointSize(2);
+	glBegin(GL_POINTS);
+
+	for (size_t i = 0; i < star_field->star_layers.size(); i++)
+	{
+		glColor4ubv(star_field->star_layers[i].colour);
+		
+		for (size_t j = 0; j < star_field->star_layers[i].stars.size(); j++)
+		{
+			glVertex2f(star_field->star_layers[i].stars[j].x, star_field->star_layers[i].stars[j].y);
+		}
+	}
+
+	glEnd();
+
+	glColor4ub(255, 255, 255, 255);
+}
+
+void DecoratorStarfield::StarField::Update()
+{
+	float time = Shell::GetElapsedTime();
+	float delta_time = time - last_update;
+	last_update = time;
+
+	if (!GameDetails::GetPaused())
+	{
+		for (size_t i = 0; i < star_layers.size(); i++)
+		{
+			float movement = star_layers[i].speed * delta_time;
+
+			for (size_t j = 0; j < star_layers[i].stars.size(); j++)
+			{
+				star_layers[i].stars[j].y += movement;
+				if (star_layers[i].stars[j].y > dimensions.y)
+				{
+					star_layers[i].stars[j].y = 0;
+					star_layers[i].stars[j].x = Rocket::Core::Math::RandomReal(dimensions.x);
+				}
+			}
+		}
+	}
+}

+ 82 - 0
Samples/luainvaders/src/DecoratorStarfield.h

@@ -0,0 +1,82 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSDECORATORSTARFIELD_H
+#define ROCKETINVADERSDECORATORSTARFIELD_H
+
+#include <Rocket/Core/Decorator.h>
+#include <vector>
+
+class DecoratorStarfield : public Rocket::Core::Decorator
+{
+public:
+	virtual ~DecoratorStarfield();
+
+	bool Initialise(int num_layers, const Rocket::Core::Colourb& top_colour, const Rocket::Core::Colourb& bottom_colour, float top_speed, float bottom_speed, int top_density, int bottom_density);
+
+	/// Called on a decorator to generate any required per-element data for a newly decorated element.
+	/// @param[in] element The newly decorated element.
+	/// @return A handle to a decorator-defined data handle, or NULL if none is needed for the element.
+	virtual Rocket::Core::DecoratorDataHandle GenerateElementData(Rocket::Core::Element* element);
+	/// Called to release element data generated by this decorator.
+	/// @param[in] element_data The element data handle to release.
+	virtual void ReleaseElementData(Rocket::Core::DecoratorDataHandle element_data);
+
+	/// Called to render the decorator on an element.
+	/// @param[in] element The element to render the decorator on.
+	/// @param[in] element_data The handle to the data generated by the decorator for the element.
+	virtual void RenderElement(Rocket::Core::Element* element, Rocket::Core::DecoratorDataHandle element_data);
+
+private:
+	int num_layers;
+	Rocket::Core::Colourb top_colour;
+	Rocket::Core::Colourb bottom_colour;
+	float top_speed;
+	float bottom_speed;
+	int top_density;
+	int bottom_density;
+
+	struct StarLayer
+	{
+		typedef std::vector< Rocket::Core::Vector2f > StarList;
+		StarList stars;
+		Rocket::Core::Colourb colour;
+		float speed;
+	};
+
+	struct StarField
+	{
+		void Update();
+		float last_update;
+		Rocket::Core::Vector2f dimensions;
+
+		typedef std::vector< StarLayer > StarLayerList;
+		StarLayerList star_layers;
+	};
+};
+
+#endif

+ 182 - 0
Samples/luainvaders/src/Defender.cpp

@@ -0,0 +1,182 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "Defender.h"
+#include <Shell.h>
+#include <ShellOpenGL.h>
+#include "Game.h"
+#include "GameDetails.h"
+#include "Invader.h"
+#include "Mothership.h"
+#include "Shield.h"
+#include "Sprite.h"
+
+const float UPDATE_FREQ = 0.01f;
+const float MOVEMENT_SPEED = 15;
+const float BULLET_SPEED = 15;
+const int SPRITE_WIDTH = 64;
+const float RESPAWN_TIME = 1.0f;
+
+Sprite defender_sprite(Rocket::Core::Vector2f(60, 31), Rocket::Core::Vector2f(0, 0.5), Rocket::Core::Vector2f(0.23437500, 0.98437500));
+Sprite bullet_sprite(Rocket::Core::Vector2f(4, 20), Rocket::Core::Vector2f(0.4921875, 0.515625), Rocket::Core::Vector2f(0.5078125, 0.828125));
+Sprite explosion_sprite(Rocket::Core::Vector2f(52, 28), Rocket::Core::Vector2f(0.71484375f, 0.51562500f), Rocket::Core::Vector2f(0.91796875f, 0.95312500f));
+
+Defender::Defender(Game* _game)
+{
+	move_direction = 0;
+	defender_frame_start = 0;
+	bullet_in_flight = false;
+	game = _game;
+	position.x = game->GetWindowDimensions().x / 2;
+	position.y = game->GetWindowDimensions().y - 50;
+	state = ALIVE;
+	render = true;
+}
+	
+Defender::~Defender()
+{
+}
+
+void Defender::Update()
+{
+	if (Shell::GetElapsedTime() - defender_frame_start < UPDATE_FREQ)
+		return;
+	
+	defender_frame_start = Shell::GetElapsedTime();	
+
+	position.x += (move_direction * MOVEMENT_SPEED);
+
+	if (position.x < 5)
+		position.x = 5;
+	else if (position.x > (game->GetWindowDimensions().x - SPRITE_WIDTH - 5))
+		position.x = game->GetWindowDimensions().x - SPRITE_WIDTH - 5;
+
+	// Update the bullet
+	if (bullet_in_flight)
+	{
+		// Move it up and mark it dead if it flies off the top of the screen
+		bullet_position.y -= BULLET_SPEED;
+		if (bullet_position.y < 0)
+			bullet_in_flight = false;
+	}
+
+	if (state == RESPAWN)
+	{	
+		// Switch the render flag so the defender "flickers"
+		render = !render;
+
+		// Check if we should switch back to our alive state
+		if (Shell::GetElapsedTime() - respawn_start > RESPAWN_TIME)
+		{
+			state = ALIVE;
+			render = true;
+		}		
+	}
+}
+
+void Defender::Render()
+{
+	glColor4ubv(GameDetails::GetDefenderColour());
+
+	// Render our sprite if rendering is enabled
+	if (render)
+		defender_sprite.Render(Rocket::Core::Vector2f(position.x, position.y));
+
+	// Update the bullet, doing collision detection
+	if (bullet_in_flight)
+	{
+		bullet_sprite.Render(Rocket::Core::Vector2f(bullet_position.x, bullet_position.y));
+
+		// Check if we hit the shields
+		for (int i = 0; i < game->GetNumShields(); i++)
+		{
+			if (game->GetShield(i)->CheckHit(bullet_position))
+			{
+				bullet_in_flight = false;
+				break;
+			}
+		}
+
+		if (bullet_in_flight)
+		{
+			for (int i = 0; i < game->GetNumInvaders(); i++)
+			{
+				if (game->GetInvader(i)->CheckHit(bullet_position))
+				{
+					bullet_in_flight = false;
+					break;
+				}
+			}
+		}
+	}
+
+	glColor4ub(255, 255, 255, 255);
+}
+
+void Defender::StartMove(float direction)
+{
+	move_direction = direction > 0.0f ? 1.0f : -1.0f;
+}
+
+void Defender::StopMove(float direction)
+{
+	float stop_direction = direction > 0.0f ? 1.0f : -1.0f;
+	if (stop_direction == move_direction)
+		move_direction = 0.0f;
+}
+
+void Defender::Fire()
+{
+	if (!bullet_in_flight)
+	{
+		bullet_position = position + Rocket::Core::Vector2f((SPRITE_WIDTH/2) - 4, 0);
+		bullet_in_flight = true;
+	}
+}
+
+bool Defender::CheckHit(const Rocket::Core::Vector2f& check_position)
+{	
+	float sprite_width = defender_sprite.dimensions.x;
+	float sprite_height = defender_sprite.dimensions.y;
+
+	// If the position is within our bounds, set ourselves
+	// as exploding and return a valid hit.
+	if (state == ALIVE
+		&& check_position.x >= position.x
+		&& check_position.x <= position.x + sprite_width
+		&& check_position.y >= position.y
+		&& check_position.y <= position.y + sprite_height)
+	{
+		game->RemoveLife();
+		state = RESPAWN;
+		respawn_start = Shell::GetElapsedTime();
+
+		return true;
+	}	
+
+	return false;
+}

+ 81 - 0
Samples/luainvaders/src/Defender.h

@@ -0,0 +1,81 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSDEFENDER_H
+#define ROCKETINVADERSDEFENDER_H
+
+#include <Rocket/Core/Types.h>
+
+class Game;
+class Sprite;
+
+/**
+	Represents the Earth defender. Stores position and performs the update of the bullet position and collision detection.
+	@author Lloyd Weehuizen
+ */
+
+class Defender
+{
+public:
+	Defender(Game* game);
+	~Defender();
+
+	/// Update the defender state.
+	void Update();
+	/// Render the defender.
+	void Render();
+
+	/// Move the defender left.
+	void StartMove(float direction);	
+	/// Stop the movement.
+	void StopMove(float direction);
+	/// Fire a bullet (if one isn't already in flight).
+	void Fire();	
+
+	/// Check if an object at the given position would hit the defender.
+	bool CheckHit(const Rocket::Core::Vector2f& position);
+
+private:
+	Game* game;
+	Rocket::Core::Vector2f position;	
+	
+	float move_direction;
+	
+	bool bullet_in_flight;
+	Rocket::Core::Vector2f bullet_position;
+
+	float defender_frame_start;
+	float respawn_start;
+
+	bool render;
+
+	enum State { ALIVE, RESPAWN };
+	State state;
+};
+
+
+#endif

+ 102 - 0
Samples/luainvaders/src/ElementGame.cpp

@@ -0,0 +1,102 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "ElementGame.h"
+#include <Rocket/Core/ElementDocument.h>
+#include <Rocket/Core/Input.h>
+#include <Rocket/Core/Factory.h>
+#include "Defender.h"
+#include "Game.h"
+
+ElementGame::ElementGame(const Rocket::Core::String& tag) : Rocket::Core::Element(tag)
+{
+	game = new Game();
+}
+
+ElementGame::~ElementGame()
+{		
+	delete game;
+}
+
+// Intercepts and handles key events.
+void ElementGame::ProcessEvent(Rocket::Core::Event& event)
+{
+	Rocket::Core::Element::ProcessEvent(event);
+
+	if (event == "keydown" ||
+		event == "keyup")
+	{
+		bool key_down = event == "keydown";
+		Rocket::Core::Input::KeyIdentifier key_identifier = (Rocket::Core::Input::KeyIdentifier) event.GetParameter< int >("key_identifier", 0);		
+
+		// Process left and right keys
+		if (key_down)
+		{
+			if (key_identifier == Rocket::Core::Input::KI_LEFT)
+				game->GetDefender()->StartMove(-1.0f);
+			if (key_identifier == Rocket::Core::Input::KI_RIGHT)
+				game->GetDefender()->StartMove(1.0f);
+			if (key_identifier == Rocket::Core::Input::KI_SPACE)
+				game->GetDefender()->Fire();
+		}		
+		else if (!key_down)
+		{
+			if (key_identifier == Rocket::Core::Input::KI_LEFT)
+				game->GetDefender()->StopMove(-1.0f);
+			if (key_identifier == Rocket::Core::Input::KI_RIGHT)
+				game->GetDefender()->StopMove(1.0f);				
+		}
+	}
+
+	if (event == "load")
+	{
+		game->Initialise();
+	}
+}
+
+// Updates the game.
+void ElementGame::OnUpdate()
+{
+	game->Update();
+
+	if (game->IsGameOver())
+		DispatchEvent("gameover", Rocket::Core::Dictionary(), false);
+}
+
+// Renders the game.
+void ElementGame::OnRender()
+{
+	game->Render();
+}
+
+void ElementGame::OnChildAdd(Rocket::Core::Element* element)
+{
+	Rocket::Core::Element::OnChildAdd(element);
+
+	if (element == this)
+		GetOwnerDocument()->AddEventListener("load", this);
+}

+ 64 - 0
Samples/luainvaders/src/ElementGame.h

@@ -0,0 +1,64 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSELEMENTGAME_H
+#define ROCKETINVADERSELEMENTGAME_H
+
+#include <Rocket/Core/Element.h>
+#include <Rocket/Core/EventListener.h>
+
+class Game;
+
+/**
+	@author Peter Curry
+ */
+
+class ElementGame : public Rocket::Core::Element, public Rocket::Core::EventListener
+{
+public:
+	ElementGame(const Rocket::Core::String& tag);
+	virtual ~ElementGame();
+
+	/// Intercepts and handles key events.
+	void ProcessEvent(Rocket::Core::Event& event);
+
+	/// Receive notifications when child elements are added
+	/// This will only get called when we're added to the tree,
+	/// which allows us to bind to onload
+	void OnChildAdd(Rocket::Core::Element* element);
+
+protected:
+	/// Updates the game.
+	virtual void OnUpdate();
+	/// Renders the game.
+	virtual void OnRender();
+
+private:
+	Game* game;
+};
+
+#endif

+ 28 - 0
Samples/luainvaders/src/ElementGameInstancer.cpp

@@ -0,0 +1,28 @@
+#include "ElementGameInstancer.h"
+#include "ElementGame.h"
+
+ElementGameInstancer::~ElementGameInstancer()
+{
+}
+	
+// Instances an element given the tag name and attributes
+Rocket::Core::Element* ElementGameInstancer::InstanceElement(Rocket::Core::Element* /*parent*/, const Rocket::Core::String& tag, const Rocket::Core::XMLAttributes& /*attributes*/)
+{
+	return new ElementGame(tag);
+}
+
+
+
+// Releases the given element
+void ElementGameInstancer::ReleaseElement(Rocket::Core::Element* element)
+{
+	delete element;
+}
+
+
+
+// Release the instancer
+void ElementGameInstancer::Release()
+{
+	delete this;
+}

+ 23 - 0
Samples/luainvaders/src/ElementGameInstancer.h

@@ -0,0 +1,23 @@
+#ifndef ELEMENTGAMEINSTANCER_H
+#define ELEMENTGAMEINSTANCER_H
+#include <Rocket/Core/ElementInstancer.h>
+
+class ElementGameInstancer : public Rocket::Core::ElementInstancer
+{
+public:
+	virtual ~ElementGameInstancer();
+	
+	/// Instances an element given the tag name and attributes
+	/// @param tag Name of the element to instance
+	/// @param attributes vector of name value pairs
+    virtual Rocket::Core::Element* InstanceElement(Rocket::Core::Element* parent, const Rocket::Core::String& tag, const Rocket::Core::XMLAttributes& attributes);
+
+	/// Releases the given element
+	/// @param element to release
+	virtual void ReleaseElement(Rocket::Core::Element* element);
+
+	/// Release the instancer
+	virtual void Release();
+};
+
+#endif

+ 445 - 0
Samples/luainvaders/src/Game.cpp

@@ -0,0 +1,445 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "Game.h"
+#include <Rocket/Core.h>
+#include <Shell.h>
+#include <ShellOpenGL.h>
+#include "Defender.h"
+#include "GameDetails.h"
+#include "HighScores.h"
+#include "Invader.h"
+#include "Mothership.h"
+#include "Shield.h"
+
+const int WINDOW_WIDTH = 1024;
+const int WINDOW_HEIGHT = 768;
+
+const int NUM_LIVES = 3;
+
+const int NUM_INVADER_ROWS = 5;
+const int NUM_INVADERS_PER_ROW = 11;
+const int NUM_INVADERS = (NUM_INVADER_ROWS * NUM_INVADERS_PER_ROW);
+const int INVADER_SPACING_X = 64;
+const int INVADER_SPACING_Y = 48;
+const int INVADER_START_Y = 96;
+
+const float INVADER_MOVEMENT = 10;
+const float INVADER_START_MOVE_FREQ = 0.5f;
+const float INVADER_UPDATE_MODIFIER = 0.7f;
+
+const int MOTHERSHIP = NUM_INVADERS;
+
+const int NUM_SHIELD_ARRAYS = 4;
+const int NUM_SHIELDS_PER_ARRAY = 10;
+const int NUM_SHIELDS = (NUM_SHIELD_ARRAYS * NUM_SHIELDS_PER_ARRAY);
+const int SHIELD_SIZE = (NUM_SHIELD_CELLS * PIXEL_SIZE);
+const int SHIELD_SPACING_X = 192;
+const int SHIELD_START_X = 176;
+const int SHIELD_START_Y = 600;
+
+// The game's element context (declared in main.cpp).
+extern Rocket::Core::Context* context;
+
+Game::Game()
+{
+	invader_frame_start = 0;
+	defender_lives = 3;	
+	game_over = false;
+	current_invader_direction = 1.0f;	
+	invaders = new Invader*[NUM_INVADERS + 1];
+	for (int i = 0; i < NUM_INVADERS + 1; i++)
+		invaders[i] = NULL;	
+
+	shields = new Shield*[NUM_SHIELDS];
+	for (int i = 0; i < NUM_SHIELDS; i++)
+		shields[i] = NULL;
+
+	// Use the OpenGL render interface to load our texture.
+	Rocket::Core::Vector2i texture_dimensions;
+	Rocket::Core::GetRenderInterface()->LoadTexture(texture, texture_dimensions, "data/invaders.tga");
+
+	defender = new Defender(this);
+}
+
+Game::~Game()
+{
+	delete defender;
+
+	for (int i = 0; i < NUM_INVADERS + 1; i++)
+		delete invaders[i];
+
+	delete [] invaders;	
+
+	for (int i = 0; i < NUM_SHIELDS; i++)
+		delete shields[i];
+
+	delete [] shields;
+}
+
+void Game::Initialise()
+{
+	// Initialise the scores and wave information
+	SetScore(0);
+	SetWave(1);
+	SetHighScore(HighScores::GetHighScore());
+	SetLives(NUM_LIVES);
+
+	// Initialise the shields.
+	InitialiseShields();
+
+	// Create a new wave
+	InitialiseWave();
+}
+
+void Game::Update()
+{
+	if (!GameDetails::GetPaused())
+	{
+		if (defender_lives <= 0)
+			return;
+
+		// Determine if we should advance the invaders
+		if (Shell::GetElapsedTime() - invader_frame_start >= invader_move_freq)
+		{
+			MoveInvaders();		
+
+			invader_frame_start = Shell::GetElapsedTime();
+		}
+
+		// Update all invaders
+		for (int i = 0; i < NUM_INVADERS + 1; i++)
+			invaders[i]->Update();	
+
+		defender->Update();
+	}
+}
+
+void Game::Render()
+{	
+	if (defender_lives <= 0)
+		return;
+
+	// Render all available shields
+	for (int i = 0; i < NUM_SHIELDS; i++)
+	{
+		shields[i]->Render();
+	}
+
+	glEnable(GL_TEXTURE_2D);
+	glBindTexture(GL_TEXTURE_2D, (GLuint) texture);
+	glColor4ub(255, 255, 255, 255);
+	glBegin(GL_QUADS);
+
+	// Render all available invaders
+	for (int i = 0; i < NUM_INVADERS + 1; i++)
+	{
+		invaders[i]->Render();
+	}
+	
+	defender->Render();
+
+	glEnd();
+}
+
+Defender* Game::GetDefender()
+{
+	return defender;
+}
+
+Invader* Game::GetInvader(int index)
+{
+	return invaders[index];
+}
+
+int Game::GetNumInvaders()
+{
+	return NUM_INVADERS + 1;
+}
+
+bool Game::CanDropBomb(int index)
+{
+	// Determines if the given invader can drop a bomb by checking if theres any other invaders under it
+	int y = (index / NUM_INVADERS_PER_ROW);
+	int x = index - (y * NUM_INVADERS_PER_ROW);
+
+	// The mothership can never drop bombs
+	if (index == MOTHERSHIP)
+		return false;
+
+	// Check each row under the given invader to see if there is space
+	for (int i = y + 1; i < NUM_INVADER_ROWS; i++)
+	{
+		if (invaders[(i * NUM_INVADERS_PER_ROW) + x]->GetState() == Invader::ALIVE)
+			return false;
+	}
+
+	return true;
+}
+
+// Access the shields.
+Shield* Game::GetShield(int index)
+{
+	return shields[index];
+}
+
+// Get the total number of shields
+int Game::GetNumShields()
+{
+	return NUM_SHIELDS;
+}
+
+// Adds a score onto the player's score.
+void Game::AddScore(int score)
+{
+	SetScore(GameDetails::GetScore() + score);
+}
+
+// Sets the player's score.
+void Game::SetScore(int score)
+{
+	GameDetails::SetScore(score);
+
+	Rocket::Core::Element* score_element = context->GetDocument("game_window")->GetElementById("score");
+	if (score_element != NULL)
+		score_element->SetInnerRML(Rocket::Core::String(128, "%d", score).CString());
+
+	// Update the high score if we've beaten it.
+	if (score > HighScores::GetHighScore())
+		SetHighScore(score);
+}
+
+// Sets the player's high-score.
+void Game::SetHighScore(int score)
+{
+	Rocket::Core::Element* high_score_element = context->GetDocument("game_window")->GetElementById("hiscore");
+	if (high_score_element != NULL)
+		high_score_element->SetInnerRML(Rocket::Core::String(128, "%d", score).CString());
+}
+
+void Game::SetLives(int lives)
+{
+	defender_lives = lives;
+
+	Rocket::Core::Element* score_element = context->GetDocument("game_window")->GetElementById("lives");
+	if (score_element != NULL)
+		score_element->SetInnerRML(Rocket::Core::String(128, "%d", defender_lives).CString());
+}
+
+void Game::SetWave(int wave)
+{
+	GameDetails::SetWave(wave);
+
+	Rocket::Core::Element* waves_element = context->GetDocument("game_window")->GetElementById("waves");
+	if (waves_element != NULL)
+		waves_element->SetInnerRML(Rocket::Core::String(128, "%d", wave).CString());
+}
+
+void Game::RemoveLife()
+{	
+	if (defender_lives > 0)
+	{
+		SetLives(defender_lives - 1);
+
+		if (defender_lives == 0)
+		{
+			OnGameOver();
+		}
+	}
+}
+
+bool Game::IsGameOver() const
+{
+	return game_over;
+}
+
+const Rocket::Core::Vector2f Game::GetWindowDimensions()
+{
+	return Rocket::Core::Vector2f((float) WINDOW_WIDTH, (float) WINDOW_HEIGHT);
+}
+
+void Game::MoveInvaders()
+{
+	Rocket::Core::Vector2f new_positions[NUM_INVADERS];
+
+	// We loop through all invaders, calculating their new positions, if any of them go over the screen bounds,
+	// then we switch direction, move the invaders down and start at 0 again
+	for (int i = 0; i < NUM_INVADERS; i++)
+	{
+		if (invaders[i]->GetState() == Invader::DEAD)
+			continue;
+
+		new_positions[i] = invaders[i]->GetPosition();
+		new_positions[i].x += INVADER_MOVEMENT * current_invader_direction;
+		if (new_positions[i].x < 0 || new_positions[i].x + INVADER_SPACING_X > WINDOW_WIDTH)
+		{
+			// Switch direction and start back at 0 (-1 as the for loop increments)
+			current_invader_direction *= -1.0f;
+			i = -1;
+
+			// Move all invaders down
+			for (int j = 0; j < NUM_INVADERS; j++)
+			{
+				if (invaders[j]->GetState() == Invader::DEAD)
+					continue;
+
+				Rocket::Core::Vector2f position = invaders[j]->GetPosition();
+				position.y += INVADER_SPACING_Y;
+				invaders[j]->SetPosition(position);
+			}
+
+			// Increase speed of invaders
+			invader_move_freq *= INVADER_UPDATE_MODIFIER;			
+		}
+	}
+
+	// Assign invaders their new position and advance their animation frame
+	bool invaders_alive = false;
+
+	for (int i = 0; i < NUM_INVADERS; i++)
+	{
+		if (invaders[i]->GetState() == Invader::DEAD)
+			continue;
+
+		invaders[i]->SetPosition(new_positions[i]);
+		invaders[i]->UpdateAnimation();
+
+		// If an invader hits the bottom, instant death
+		if (new_positions[i].y >= GetWindowDimensions().y - INVADER_SPACING_Y)
+		{
+			OnGameOver();
+			return;
+		}
+
+		invaders_alive = true;
+	}
+
+	if (!invaders_alive)
+	{
+		SetWave(GameDetails::GetWave() + 1);
+		InitialiseWave();
+	}
+}
+
+void Game::OnGameOver()
+{
+	// Set lives to zero and continue to the high scores
+	defender_lives = 0;
+	game_over = true;
+}
+
+void Game::InitialiseShields()
+{
+	Rocket::Core::Vector2f shield_array_start_position((float) SHIELD_START_X, (float) SHIELD_START_Y);
+
+	for (int x = 0; x < NUM_SHIELD_ARRAYS; x++)
+	{
+		// Top row (row of 4)
+		for (int i = 0; i < 4; i++)
+		{
+			Shield::ShieldType type = Shield::REGULAR;
+			if (i == 0)
+				type = Shield::TOP_LEFT;
+			else if (i == 3)
+			{
+				type = Shield::TOP_RIGHT;
+			}
+
+			shields[(x * NUM_SHIELDS_PER_ARRAY) + i] = new Shield(this, type);
+			shields[(x * NUM_SHIELDS_PER_ARRAY) + i]->SetPosition(shield_array_start_position + Rocket::Core::Vector2f((float) SHIELD_SIZE * i, 0));
+		}
+
+		// Middle row (row of 4)
+		for (int i = 0; i < 4; i++)
+		{
+			
+			Shield::ShieldType type = Shield::REGULAR;
+			if (i == 1)
+				type = Shield::BOTTOM_RIGHT;
+			else if (i == 2)
+			{
+				type = Shield::BOTTOM_LEFT;
+			}
+
+			shields[(x * NUM_SHIELDS_PER_ARRAY) + 4 + i] = new Shield(this, type);
+			shields[(x * NUM_SHIELDS_PER_ARRAY) + 4 + i]->SetPosition(shield_array_start_position + Rocket::Core::Vector2f((float) SHIELD_SIZE * i, (float) SHIELD_SIZE));
+		}
+
+		// Bottom row (2, one on each end)
+		shields[(x * NUM_SHIELDS_PER_ARRAY) + 8] = new Shield(this, Shield::REGULAR);
+		shields[(x * NUM_SHIELDS_PER_ARRAY) + 8]->SetPosition(shield_array_start_position + Rocket::Core::Vector2f(0, (float) SHIELD_SIZE * 2));
+
+		shields[(x * NUM_SHIELDS_PER_ARRAY) + 9] = new Shield(this, Shield::REGULAR);
+		shields[(x * NUM_SHIELDS_PER_ARRAY) + 9]->SetPosition(shield_array_start_position + Rocket::Core::Vector2f((float) SHIELD_SIZE * 3, (float) SHIELD_SIZE * 2));
+
+		shield_array_start_position.x += SHIELD_SPACING_X;
+	}
+}
+
+void Game::InitialiseWave()
+{
+	// Set up the rows
+	for (int y = 0; y < NUM_INVADER_ROWS; y++)
+	{
+		// Determine invader type
+		Invader::InvaderType type = Invader::UNKNOWN;
+		switch (y)
+		{
+		case 0:
+			type = Invader::RANK3; break;
+		case 1:
+		case 2:		
+			type = Invader::RANK2; break;
+		default:
+			type = Invader::RANK1; break;
+		}
+
+		// Determine position of top left invader
+		Rocket::Core::Vector2f invader_position((float) (WINDOW_WIDTH - (NUM_INVADERS_PER_ROW * INVADER_SPACING_X)) / 2, (float) (INVADER_START_Y + (y * INVADER_SPACING_Y)));
+	
+		for (int x = 0; x < NUM_INVADERS_PER_ROW; x++)
+		{
+			// Determine invader type based on row position
+			int index = (y * NUM_INVADERS_PER_ROW) + x;
+
+			delete invaders[index];
+			invaders[index] = new Invader(this, type, (y * NUM_INVADERS_PER_ROW) + x);			
+			invaders[index]->SetPosition(invader_position);			
+
+			// Increase invader position
+			invader_position.x += INVADER_SPACING_X;
+		}
+	}
+
+	// Reset mother ship
+	delete invaders[MOTHERSHIP];
+	invaders[MOTHERSHIP] = new Mothership(this, MOTHERSHIP);
+
+	// Update the move frequency	
+	invader_move_freq = ((((float)GameDetails::GetWave())-100.0f)/140.0f);
+	invader_move_freq *= invader_move_freq;
+}

+ 128 - 0
Samples/luainvaders/src/Game.h

@@ -0,0 +1,128 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSGAME_H
+#define ROCKETINVADERSGAME_H
+
+#include <Rocket/Core/Types.h>
+#include <Rocket/Core/Texture.h>
+
+class Shield;
+class Invader;
+class Defender;
+class Mothership;
+
+/**
+	Runs the game.
+	- Updates the Invader positions, animations and bombs.
+	- Updates the player position and bullets
+
+	@author Lloyd Weehuizen
+ */
+
+class Game
+{
+public:
+	Game();
+	~Game();
+
+	/// Initialise a new game
+	void Initialise();
+
+	/// Update the game
+	void Update();
+
+	/// Render the game
+	void Render();
+
+	/// Access the defender
+	Defender* GetDefender();
+	/// Access the invaders
+	Invader* GetInvader(int index);
+	/// Get the total number of invaders
+	int GetNumInvaders();
+
+	/// Returns true if the given invader can drop bomb
+	bool CanDropBomb(int invader_index);
+
+	/// Access the shields.
+	Shield* GetShield(int index);
+	/// Get the total number of shields
+	int GetNumShields();
+
+	/// Adds a score onto the player's score.
+	void AddScore(int score);
+	/// Sets the player's score.
+	void SetScore(int score);
+	/// Sets the player's high-score.
+	void SetHighScore(int score);
+	/// Set the number of defender lives.
+	void SetLives(int lives);
+	/// Set the current wave
+	void SetWave(int wave);
+	/// Remove a defender life
+	void RemoveLife();
+	/// Checks if the game is over
+	bool IsGameOver() const;
+
+	/// Get the dimensions of the game window.
+	const Rocket::Core::Vector2f GetWindowDimensions();	
+
+private:
+
+	// The current invaders
+	Invader** invaders;
+	// The direction they're moving
+	float current_invader_direction;
+	// Time of the last invader update
+	Rocket::Core::Time invader_frame_start;
+	// How often the invaders move
+	Rocket::Core::Time invader_move_freq;
+	// Is the game over
+	bool game_over;
+
+	// Helper function to move the invaders
+	void MoveInvaders();
+
+	// Our current defener
+	Defender* defender;
+
+	// Number of lives the defender has left
+	int defender_lives;
+
+	// The current shields
+	Shield** shields;
+
+	// Texture that contains the sprites
+	Rocket::Core::TextureHandle texture;
+
+	void InitialiseShields();
+	void InitialiseWave();
+	void OnGameOver();
+};
+
+#endif

+ 148 - 0
Samples/luainvaders/src/GameDetails.cpp

@@ -0,0 +1,148 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "GameDetails.h"
+
+static GameDetails::Difficulty difficulty = GameDetails::EASY;
+static Rocket::Core::Colourb colour = Rocket::Core::Colourb(255, 0, 0);
+static int score = -1;
+static int wave = 0;
+static bool paused = false;
+
+static GameDetails::GraphicsQuality graphics_quality = GameDetails::OK;
+static bool reverb = true;
+static bool spatialisation = false;
+
+GameDetails::GameDetails()
+{
+}
+
+GameDetails::~GameDetails()
+{
+}
+
+// Sets the game difficulty.
+void GameDetails::SetDifficulty(Difficulty _difficulty)
+{
+	difficulty = _difficulty;
+}
+
+// Returns the game difficulty.
+GameDetails::Difficulty GameDetails::GetDifficulty()
+{
+	return difficulty;
+}
+
+// Sets the colour of the player's ship.
+void GameDetails::SetDefenderColour(const Rocket::Core::Colourb& _colour)
+{
+	colour = _colour;
+}
+
+// Returns the player's ship colour.
+const Rocket::Core::Colourb& GameDetails::GetDefenderColour()
+{
+	return colour;
+}
+
+// Sets the score the player achieved in the last game.
+void GameDetails::SetScore(int _score)
+{
+	score = _score;
+}
+
+// Resets the player's score.
+void GameDetails::ResetScore()
+{
+	score = -1;
+}
+
+// Returns the score the player achieved in the last game.
+int GameDetails::GetScore()
+{
+	return score;
+}
+
+// Set the current wave number
+void GameDetails::SetWave(int _wave)
+{
+	wave = _wave;
+}
+
+// Get the current wave number
+int GameDetails::GetWave()
+{
+	return wave;
+}
+
+// Sets the pauses state of the game
+void GameDetails::SetPaused(bool _paused)
+{
+	paused = _paused;
+}
+
+// Gets if the game is paused or not
+bool GameDetails::GetPaused()
+{
+	return paused;
+}
+
+// Sets the quality of the graphics used in-game.
+void GameDetails::SetGraphicsQuality(GraphicsQuality quality)
+{
+	graphics_quality = quality;
+}
+
+// Returns the quality of the graphics to use in-game.
+GameDetails::GraphicsQuality GameDetails::GetGraphicsQuality()
+{
+	return graphics_quality;
+}
+
+// Enables or disables reverb.
+void GameDetails::SetReverb(bool enabled)
+{
+	reverb = enabled;
+}
+
+// Returns the current state of reverb.
+bool GameDetails::GetReverb()
+{
+	return reverb;
+}
+
+// Enables or disables 3D spatialisation in the audio engine.
+void GameDetails::Set3DSpatialisation(bool enabled)
+{
+	spatialisation = enabled;
+}
+
+// Returns the current state of audio spatialisation.
+bool GameDetails::Get3DSpatialisation()
+{
+	return spatialisation;
+}

+ 107 - 0
Samples/luainvaders/src/GameDetails.h

@@ -0,0 +1,107 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSGAMEDETAILS_H
+#define ROCKETINVADERSGAMEDETAILS_H
+
+#include <Rocket/Core/Types.h>
+
+/**
+	@author Peter Curry
+ */
+
+class GameDetails
+{
+public:
+	enum Difficulty { EASY, HARD };
+
+	/// Sets the game difficulty.
+	/// @param[in] difficulty The new game difficulty.
+	static void SetDifficulty(Difficulty difficulty);
+	/// Returns the game difficulty.
+	/// @return The current game difficulty.
+	static Difficulty GetDifficulty();
+
+	/// Sets the colour of the player's ship.
+	/// @param[in] colour The new ship colour.
+	static void SetDefenderColour(const Rocket::Core::Colourb& colour);
+	/// Returns the player's ship colour.
+	/// @return The colour of the player's ship.
+	static const Rocket::Core::Colourb& GetDefenderColour();
+
+	/// Sets the score the player achieved in the last game.
+	/// @param[in] score The player's score.
+	static void SetScore(int score);
+	/// Resets the player's score.
+	static void ResetScore();
+	/// Returns the score the player achieved in the last game.
+	/// @return The player's score.
+	static int GetScore();
+
+	/// Sets the current wave number
+	/// @param[in] wave The wave number
+	static void SetWave(int wave);
+	/// Get the current wave number
+	/// @return The wave number
+	static int GetWave();
+
+	/// Sets the pauses state of the game
+	/// @param[in] paused Whether the game is paused or not
+	static void SetPaused(bool paused);
+	/// Gets if the game is paused or not
+	/// @return True if the game is paused, false otherwise.
+	static bool GetPaused();
+
+	enum GraphicsQuality { GOOD, OK, BAD };
+
+	/// Sets the quality of the graphics used in-game.
+	/// @param[in] quality The new graphics quality.
+	static void SetGraphicsQuality(GraphicsQuality quality);
+	/// Returns the quality of the graphics to use in-game.
+	/// @return The currently-set graphical quality.
+	static GraphicsQuality GetGraphicsQuality();
+
+	/// Enables or disables reverb.
+	/// @param[in] enabled True to enable reverb, false to disable.
+	static void SetReverb(bool enabled);
+	/// Returns the current state of reverb.
+	/// @return The current reverb state.
+	static bool GetReverb();
+
+	/// Enables or disables 3D spatialisation in the audio engine.
+	/// @param[in] enabled True to enable spatialisation, false to disable.
+	static void Set3DSpatialisation(bool enabled);
+	/// Returns the current state of audio spatialisation.
+	/// @return The current audio spatialisation state.
+	static bool Get3DSpatialisation();
+
+private:
+	GameDetails();
+	~GameDetails();
+};
+
+#endif

+ 236 - 0
Samples/luainvaders/src/HighScores.cpp

@@ -0,0 +1,236 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "HighScores.h"
+#include <Rocket/Core/TypeConverter.h>
+#include <stdio.h>
+
+HighScores* HighScores::instance = NULL;
+
+HighScores::HighScores() : Rocket::Controls::DataSource("high_scores")
+{
+	ROCKET_ASSERT(instance == NULL);
+	instance = this;
+
+	for (int i = 0; i < NUM_SCORES; i++)
+	{
+		scores[i].score = -1;
+	}
+
+	LoadScores();
+}
+
+HighScores::~HighScores()
+{
+	ROCKET_ASSERT(instance == this);
+
+	SaveScores();
+
+	instance = NULL;
+}
+
+void HighScores::Initialise()
+{
+	new HighScores();
+}
+
+void HighScores::Shutdown()
+{
+	delete instance;
+}
+
+void HighScores::GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int row_index, const Rocket::Core::StringList& columns)
+{
+	if (table == "scores")
+	{
+		for (size_t i = 0; i < columns.size(); i++)
+		{
+			if (columns[i] == "name")
+			{
+				row.push_back(scores[row_index].name);
+			}
+			else if (columns[i] == "name_required")
+			{
+				row.push_back(Rocket::Core::String(4, "%d", scores[row_index].name_required));
+			}
+			else if (columns[i] == "score")
+			{
+				row.push_back(Rocket::Core::String(32, "%d", scores[row_index].score));
+			}
+			else if (columns[i] == "colour")
+			{
+				Rocket::Core::String colour_string;
+				Rocket::Core::TypeConverter< Rocket::Core::Colourb, Rocket::Core::String >::Convert(scores[row_index].colour, colour_string);
+				row.push_back(colour_string);
+			}
+			else if (columns[i] == "wave")
+			{
+				row.push_back(Rocket::Core::String(8, "%d", scores[row_index].wave));
+			}
+		}
+	}
+}
+
+int HighScores::GetNumRows(const Rocket::Core::String& table)
+{
+	if (table == "scores")
+	{
+		for (int i = 0; i < NUM_SCORES; i++)
+		{
+			if (scores[i].score == -1)
+			{
+				return i;
+			}
+		}
+
+		return NUM_SCORES;
+	}
+
+	return 0;
+}
+
+int HighScores::GetHighScore()
+{
+	if (instance->GetNumRows("scores") == 0)
+	{
+		return 0;
+	}
+
+	return instance->scores[0].score;
+}
+
+void HighScores::SubmitScore(const Rocket::Core::String& name, const Rocket::Core::Colourb& colour, int wave, int score)
+{
+	instance->SubmitScore(name, colour, wave, score, false);
+}
+
+void HighScores::SubmitScore(const Rocket::Core::Colourb& colour, int wave, int score)
+{
+	instance->SubmitScore("", colour, wave, score, true);
+}
+
+// Sets the name of the last player to submit their score.
+void HighScores::SubmitName(const Rocket::Core::String& name)
+{
+	for (int i = 0; i < instance->GetNumRows("scores"); i++)
+	{
+		if (instance->scores[i].name_required)
+		{
+			instance->scores[i].name = name;
+			instance->scores[i].name_required = false;
+			instance->NotifyRowChange("scores", i, 1);
+		}
+	}
+}
+
+void HighScores::SubmitScore(const Rocket::Core::String& name, const Rocket::Core::Colourb& colour, int wave, int score, bool name_required)
+{
+	for (int i = 0; i < NUM_SCORES; i++)
+	{
+		if (score > scores[i].score)
+		{
+			// If we've already got the maximum number of scores, then we have
+			// to send a RowsRemoved message as we're going to delete the last
+			// row from the data source.
+			bool max_rows = scores[NUM_SCORES - 1].score != -1;
+
+			// Push down all the other scores.
+			for (int j = NUM_SCORES - 1; j > i; j--)
+			{
+				scores[j] = scores[j - 1];
+			}
+
+			// Insert our new score.
+			scores[i].name = name;
+			scores[i].colour = colour;
+			scores[i].wave = wave;
+			scores[i].score = score;
+			scores[i].name_required = name_required;
+
+			// Send the row removal message (if necessary).
+			if (max_rows)
+			{
+				NotifyRowRemove("scores", NUM_SCORES - 1, 1);
+			}
+
+			// Then send the rows added message.
+			NotifyRowAdd("scores", i, 1);
+
+			return;
+		}
+	}
+}
+
+void HighScores::LoadScores()
+{
+	// Open and read the high score file.
+	FILE* scores_file = fopen("scores.txt", "rt");
+
+	if (scores_file)
+	{
+		char buffer[1024];
+		while (fgets(buffer, 1024, scores_file))
+		{
+			Rocket::Core::StringList score_parts;
+			Rocket::Core::StringUtilities::ExpandString(score_parts, Rocket::Core::String(buffer), '\t');
+			if (score_parts.size() == 4)
+			{
+				Rocket::Core::Colourb colour;
+				int wave;
+				int score;
+
+				if (Rocket::Core::TypeConverter< Rocket::Core::String , Rocket::Core::Colourb >::Convert(score_parts[1], colour) &&
+					Rocket::Core::TypeConverter< Rocket::Core::String, int >::Convert(score_parts[2], wave) &&
+					Rocket::Core::TypeConverter< Rocket::Core::String, int >::Convert(score_parts[3], score))
+				{
+					SubmitScore(score_parts[0], colour, wave, score);
+				}
+			}
+		}
+
+		fclose(scores_file);
+	}
+}
+
+void HighScores::SaveScores()
+{
+	FILE* scores_file = fopen("scores.txt", "wt");
+
+	if (scores_file)
+	{
+		for (int i = 0; i < GetNumRows("scores"); i++)
+		{
+			Rocket::Core::String colour_string;
+			Rocket::Core::TypeConverter< Rocket::Core::Colourb, Rocket::Core::String >::Convert(scores[i].colour, colour_string);
+
+			Rocket::Core::String score(1024, "%s\t%s\t%d\t%d\n", scores[i].name.CString(), colour_string.CString(), scores[i].wave, scores[i].score);
+			fputs(score.CString(), scores_file);		
+		}
+
+		fclose(scores_file);
+	}
+}

+ 77 - 0
Samples/luainvaders/src/HighScores.h

@@ -0,0 +1,77 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSHIGHSCORES_H
+#define ROCKETINVADERSHIGHSCORES_H
+
+#include <Rocket/Controls/DataSource.h>
+#include <Rocket/Core/Types.h>
+
+const int NUM_SCORES = 10;
+
+class HighScores : public Rocket::Controls::DataSource
+{
+public:
+	static void Initialise();
+	static void Shutdown();
+
+	void GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int row_index, const Rocket::Core::StringList& columns);
+	int GetNumRows(const Rocket::Core::String& table);
+
+	static int GetHighScore();
+
+	/// Two functions to add a score to the chart.
+	/// Adds a full score, including a name. This won't prompt the user to enter their name.
+	static void SubmitScore(const Rocket::Core::String& name, const Rocket::Core::Colourb& colour, int wave, int score);
+	/// Adds a score, and causes an input field to appear to request the user for their name.
+	static void SubmitScore(const Rocket::Core::Colourb& colour, int wave, int score);
+	/// Sets the name of the last player to submit their score.
+	static void SubmitName(const Rocket::Core::String& name);
+
+private:
+	HighScores();
+	~HighScores();
+
+	static HighScores* instance;
+
+	void SubmitScore(const Rocket::Core::String& name, const Rocket::Core::Colourb& colour, int wave, int score, bool name_required);
+	void LoadScores();
+	void SaveScores();
+
+	struct Score
+	{
+		Rocket::Core::String name;
+		bool name_required;
+		Rocket::Core::Colourb colour;
+		int score;
+		int wave;
+	};
+
+	Score scores[NUM_SCORES];
+};
+
+#endif

+ 266 - 0
Samples/luainvaders/src/Invader.cpp

@@ -0,0 +1,266 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "Invader.h"
+#include <Rocket/Core/Math.h>
+#include <Shell.h>
+#include <ShellOpenGL.h>
+#include "Defender.h"
+#include "Game.h"
+#include "GameDetails.h"
+#include "Shield.h"
+#include "Sprite.h"
+
+const float BOMB_UPDATE_FREQ = 0.04f;
+const float BOMB_RAY_SPEED = 10;
+const float BOMB_MISSILE_SPEED = 7;
+const float BOMB_PROBABILITY_EASY = 0.002f;
+const float BOMB_PROBABILITY_HARD = 0.005f;
+const float EXPLOSION_TIME = 0.25f;
+const Rocket::Core::Colourb MOTHERSHIP_COLOUR = Rocket::Core::Colourb(255, 0, 0, 255);
+
+Sprite invader_sprites[] =
+{
+	// Rank 1
+	Sprite(Rocket::Core::Vector2f(48, 32), Rocket::Core::Vector2f(0.609375f, 0), Rocket::Core::Vector2f(0.796875f, 0.5f)),
+	Sprite(Rocket::Core::Vector2f(48, 32), Rocket::Core::Vector2f(0.80078125f, 0), Rocket::Core::Vector2f(0.98828125f, 0.5f)),
+	// Rank 2
+	Sprite(Rocket::Core::Vector2f(44, 32), Rocket::Core::Vector2f(0.2578125f, 0), Rocket::Core::Vector2f(0.4296875f, 0.5f)),
+	Sprite(Rocket::Core::Vector2f(44, 32), Rocket::Core::Vector2f(0.43359375f, 0), Rocket::Core::Vector2f(0.60546875f, 0.5f)),
+	// Rank 3
+	Sprite(Rocket::Core::Vector2f(32, 32), Rocket::Core::Vector2f(0, 0), Rocket::Core::Vector2f(0.125f, 0.5f)),
+	Sprite(Rocket::Core::Vector2f(32, 32), Rocket::Core::Vector2f(0.12890625f, 0), Rocket::Core::Vector2f(0.25390625f, 0.5f)),
+	// Mothership
+	Sprite(Rocket::Core::Vector2f(64, 28), Rocket::Core::Vector2f(0.23828125f, 0.515625f), Rocket::Core::Vector2f(0.48828125f, 0.953125f)),
+	// Explosion
+	Sprite(Rocket::Core::Vector2f(52, 28), Rocket::Core::Vector2f(0.71484375f, 0.51562500f), Rocket::Core::Vector2f(0.91796875f, 0.95312500f))	
+};
+
+Sprite bomb_sprites[] =
+{
+	// Ray
+	Sprite(Rocket::Core::Vector2f(12, 20), Rocket::Core::Vector2f(0.51171875f, 0.51562500f), Rocket::Core::Vector2f(0.55859375f, 0.82812500f)),
+	Sprite(Rocket::Core::Vector2f(12, 20), Rocket::Core::Vector2f(0.56250000, 0.51562500), Rocket::Core::Vector2f(0.60937500, 0.82812500)),
+	Sprite(Rocket::Core::Vector2f(12, 20), Rocket::Core::Vector2f(0.61328125, 0.51562500), Rocket::Core::Vector2f(0.66015625, 0.82812500)),
+	Sprite(Rocket::Core::Vector2f(12, 20), Rocket::Core::Vector2f(0.66406250, 0.51562500), Rocket::Core::Vector2f(0.71093750, 0.82812500)),
+	// Missile
+	Sprite(Rocket::Core::Vector2f(12, 20), Rocket::Core::Vector2f(0.92578125, 0.51562500), Rocket::Core::Vector2f(0.97265625, 0.82812500))
+};
+
+Invader::Invader(Game* _game, InvaderType _type, int _index) : position(0,0)
+{
+	type = UNKNOWN;
+	animation_frame = 0;
+	bomb_animation_frame = 0;
+	bomb_frame_start = 0;
+	death_time = 0;
+	state = ALIVE;
+	bomb = NONE;
+	game = _game;
+	type = _type;
+	death_time = 0;
+	invader_index = _index;
+
+	bomb_probability = GameDetails::GetDifficulty() == GameDetails::EASY ? BOMB_PROBABILITY_EASY : BOMB_PROBABILITY_HARD;
+	bomb_probability *= type;
+}
+
+Invader::~Invader()
+{
+}
+
+void Invader::SetPosition(const Rocket::Core::Vector2f& _position)
+{
+	position = _position;
+}
+
+const Rocket::Core::Vector2f& Invader::GetPosition() const
+{
+	return position;
+}
+
+void Invader::Update()
+{
+	// Update the bombs
+	if (Shell::GetElapsedTime() - bomb_frame_start > BOMB_UPDATE_FREQ)
+	{	
+
+		// Update the bomb position if its in flight, or check if we should drop one
+		if (bomb != NONE)
+		{
+			if (bomb == RAY)
+			{
+				bomb_animation_frame++;
+				if (bomb_animation_frame > 3)
+					bomb_animation_frame = 0;
+
+				bomb_position.y += BOMB_RAY_SPEED;
+			}
+			else
+			{
+				bomb_position.y += BOMB_MISSILE_SPEED;
+			}
+			
+			if (bomb_position.y > game->GetWindowDimensions().y)
+				bomb = NONE;
+
+			// Check if we hit the shields
+			for (int i = 0; i < game->GetNumShields(); i++)
+			{
+				if (game->GetShield(i)->CheckHit(bomb_position))
+				{
+					bomb = NONE;
+					break;
+				}
+			}
+
+			// Check if we hit the defender
+			if (bomb != NONE)
+			{
+				if (game->GetDefender()->CheckHit(bomb_position))
+					bomb = NONE;
+			}
+		}
+		else if (state == ALIVE &&
+				 Rocket::Core::Math::RandomReal(1.0f) < bomb_probability &&
+				 game->CanDropBomb(invader_index))
+		{
+			bomb = Rocket::Core::Math::RandomInteger(2) == 0 ? RAY : MISSILE;
+			bomb_position = position;
+			bomb_position.x += invader_sprites[GetSpriteIndex()].dimensions.x / 2;
+
+			if (bomb == RAY)
+				bomb_animation_frame = 0;
+			else
+				bomb_animation_frame = 4;
+		}	
+
+		bomb_frame_start = Shell::GetElapsedTime();
+	}
+
+	if (state == EXPLODING && Shell::GetElapsedTime() > death_time)
+		state = DEAD;
+}
+
+void Invader::UpdateAnimation()
+{
+	switch (state)
+	{
+	case ALIVE:
+		animation_frame++;
+		if (animation_frame > 1)
+			animation_frame = 0;
+		break;
+
+	default:
+		break;
+	}
+}
+
+void Invader::Render()
+{
+	if (type == MOTHERSHIP)
+	{
+		glColor4ubv(MOTHERSHIP_COLOUR);
+	}
+	int sprite_index = GetSpriteIndex();
+	int sprite_offset = Rocket::Core::Math::RealToInteger((invader_sprites[sprite_index].dimensions.x - 48) / 2);
+
+	if (state != DEAD)
+		invader_sprites[sprite_index].Render(Rocket::Core::Vector2f(position.x - sprite_offset, position.y));
+	
+	if (bomb != NONE)
+	{
+		bomb_sprites[bomb_animation_frame].Render(bomb_position);
+	}
+
+	if (type == MOTHERSHIP)
+	{
+		glColor4ub(255, 255, 255, 255);
+	}
+}
+
+Invader::InvaderState Invader::GetState()
+{
+	return state;
+}
+
+bool Invader::CheckHit(const Rocket::Core::Vector2f& check_position)
+{
+	// Get the sprite index we're currently using for collision detection
+	int sprite_index = GetSpriteIndex();
+	int sprite_offset = Rocket::Core::Math::RealToInteger((invader_sprites[sprite_index].dimensions.x - 48) / 2);
+	float sprite_width = invader_sprites[sprite_index].dimensions.x;
+	float sprite_height = invader_sprites[sprite_index].dimensions.y;
+
+	// If we're alive and the position is within our bounds, set ourselves
+	// as exploding and return a valid hit
+	if (state == ALIVE
+		&& check_position.x >= position.x - sprite_offset
+		&& check_position.x <= position.x - sprite_offset + sprite_width
+		&& check_position.y >= position.y
+		&& check_position.y <= position.y + sprite_height)
+	{
+		int score = 0;
+		switch (type)
+		{
+			case MOTHERSHIP: score = (Rocket::Core::Math::RandomInteger(6) + 1) * 50; break;	// 50 -> 300
+			case RANK3: score = 40; break;
+			case RANK2: score = 20; break;
+			case RANK1: score = 10; break;
+		}
+
+		// Add the number of points
+		game->AddScore(score);
+
+		// Set our state to exploding and start the timer to our doom
+		state = EXPLODING;
+		death_time = Shell::GetElapsedTime() + EXPLOSION_TIME;	
+
+		return true;
+	}
+
+	return false;
+}
+
+int Invader::GetSpriteIndex() const
+{
+	// Calculate our sprite index based on animation and type
+	int index = animation_frame;
+	switch (type)
+	{
+		case RANK2:	index += 2; break;
+		case RANK3:	index += 4; break;
+		case MOTHERSHIP: index = 6; break;
+	}
+
+	// If we're in exploding state, use the exploding sprite
+	if (state == EXPLODING)
+		index = 7;
+
+	return index;
+}

+ 114 - 0
Samples/luainvaders/src/Invader.h

@@ -0,0 +1,114 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSINVADER_H
+#define ROCKETINVADERSINVADER_H
+
+#include <Rocket/Core/Types.h>
+
+class Game;
+
+/**
+	An alien invader.
+
+	@author Lloyd Weehuizen
+ */
+
+class Invader
+{
+public:	
+	enum InvaderType { UNKNOWN, RANK1, RANK2, RANK3, MOTHERSHIP };
+	enum BombType { NONE, RAY, MISSILE };
+
+	/// Construct the invader
+	Invader(Game* game, InvaderType type, int index);
+	~Invader();	
+
+	/// Set the invaders screen position
+	/// @param position Position in screen space
+	void SetPosition(const Rocket::Core::Vector2f& position);
+	/// Get the current invader position
+	/// @returns The invaders position in screen space
+	const Rocket::Core::Vector2f& GetPosition() const;
+
+	/// Update the invader
+	virtual void Update();	
+
+	/// Render the invader
+	void Render();
+
+	/// Update the invaders animation
+	void UpdateAnimation();
+
+	/// The current invaders state
+	enum InvaderState { ALIVE, EXPLODING, DEAD };
+	/// Get the current invader state
+	/// @returns Invader state
+	InvaderState GetState();
+
+	/// Returns true if the position hits the invader
+	/// If a hit is detected, will explode and start the death timer
+	/// @param position Position to do the hit check at
+	/// @returns If the invader was hit
+	bool CheckHit(const Rocket::Core::Vector2f& position);
+
+protected:
+	// Game this invader is in
+	Game* game;
+	// The index/id of this invader
+	int invader_index;
+
+	// The invader type we represent
+	InvaderType type;
+	// The current position in screen space of the invader
+	Rocket::Core::Vector2f position;
+	// Our current animation frame
+	int animation_frame;
+
+	// Our current state
+	InvaderState state;
+
+	// Our current in-flight bomb, or none. (may be not none if we're dead.)
+	BombType bomb;
+	// The current position of the bomb in screen space
+	Rocket::Core::Vector2f bomb_position;
+	// The animation frame the bomb is on
+	int bomb_animation_frame;
+	// When the last bomb update occured
+	float bomb_frame_start;
+	// Probability of us dropping a bomb - this is calculated
+	// at construction time and based on our rank and the game
+	// difficulty level
+	float bomb_probability;
+
+	// Time when we should die - 0, until we're hit
+	float death_time;	
+
+	int GetSpriteIndex() const;
+};
+
+#endif

+ 117 - 0
Samples/luainvaders/src/LuaInterface.cpp

@@ -0,0 +1,117 @@
+#include "LuaInterface.h"
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include "Game.h"
+#include "GameDetails.h"
+#include <Rocket/Core/Log.h>
+#include <Shell.h>
+#include <Rocket/Core/Factory.h>
+#include "HighScores.h"
+#include <Rocket/Core/Types.h>
+#include "ElementGameInstancer.h"
+
+//we have to create the binding ourselves, and these are the functions that will be
+//called. It has to match the function signature of int (*ftnptr)(lua_State*)
+int GameShutdown(lua_State* L);
+int GameSetPaused(lua_State* L);
+int GameSetDifficulty(lua_State* L);
+int GameSetDefenderColour(lua_State* L);
+int GameSubmitHighScore(lua_State* L);
+int GameSetHighScoreName(lua_State* L);
+
+void LuaInterface::Initialise(lua_State* L)
+{
+    InitGame(L);
+    Rocket::Core::Factory::RegisterElementInstancer("game",new ElementGameInstancer())->RemoveReference();
+}
+
+void LuaInterface::InitGame(lua_State *L)
+{
+    luaL_dostring(L,"Game = Game or {}"); //doing this in Lua because it would be 10+ lines in C++
+    lua_getglobal(L,"Game");
+    int game = lua_gettop(L);
+
+    if(lua_isnil(L,game))
+    {
+        Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Error creating the Game table from C++ in LuaInterface::InitGame");
+        return;
+    }
+    
+    //this can be done in a loop similar to the implementation of LuaType::_regfunctions, but I am
+    //defining them explicitly so that there is no black magic
+    lua_pushcfunction(L,GameShutdown);
+    lua_setfield(L, game, "Shutdown");
+
+    lua_pushcfunction(L,GameSetPaused);
+    lua_setfield(L,game,"SetPaused");
+
+    lua_pushcfunction(L,GameSetDifficulty);
+    lua_setfield(L,game,"SetDifficulty");
+
+    lua_pushcfunction(L,GameSetDefenderColour);
+    lua_setfield(L,game,"SetDefenderColour");
+
+    lua_pushcfunction(L,GameSubmitHighScore);
+    lua_setfield(L,game,"SubmitHighScore");
+
+    lua_pushcfunction(L,GameSetHighScoreName);
+    lua_setfield(L,game,"SetHighScoreName");
+
+    lua_newtable(L); //table, Game
+    lua_pushinteger(L,GameDetails::HARD); //int,table,Game
+    lua_setfield(L,-2,"HARD");//table,Game
+
+    lua_pushinteger(L,GameDetails::EASY); //int,table,Game
+    lua_setfield(L,-2,"EASY"); //table,Game
+
+    lua_setfield(L,game,"difficulty"); //Game
+
+    lua_pop(L,1); //pop Game
+}
+
+int GameShutdown(lua_State* L)
+{
+    Shell::RequestExit();
+    return 0;
+}
+
+int GameSetPaused(lua_State* L)
+{
+    bool paused = CHECK_BOOL(L,1); //CHECK_BOOL defined in LuaType.h
+    GameDetails::SetPaused(paused);
+    return 0;
+}
+
+int GameSetDifficulty(lua_State* L)
+{
+    int difficulty = luaL_checkint(L,1);
+    GameDetails::SetDifficulty((GameDetails::Difficulty)difficulty);
+    return 0;
+}
+
+int GameSetDefenderColour(lua_State* L)
+{
+    Rocket::Core::Colourb* colour = Rocket::Core::Lua::LuaType<Rocket::Core::Colourb>::check(L,1);
+    GameDetails::SetDefenderColour(*colour);
+    return 0;
+}
+
+int GameSubmitHighScore(lua_State* L)
+{
+    int score = GameDetails::GetScore();
+    if(score > 0)
+    {
+        // Submit the score the player just got to the high scores chart.
+        HighScores::SubmitScore(GameDetails::GetDefenderColour(),GameDetails::GetWave(), GameDetails::GetScore());
+        // Reset the score so the chart won't get confused next time we enter.
+        GameDetails::ResetScore();
+    }
+    return 0;
+}
+
+int GameSetHighScoreName(lua_State* L)
+{
+    const char* name = luaL_checkstring(L,1);
+    HighScores::SubmitName(name);
+    return 0;
+}

+ 27 - 0
Samples/luainvaders/src/LuaInterface.h

@@ -0,0 +1,27 @@
+#ifndef LUAINTERFACE_H
+#define LUAINTERFACE_H 
+/*
+    This will define the "Game" global table in Lua and some functions with it.
+
+    In Lua, the skeleton definition of Game with the fake function definitions (because it calls c++ code) would look something like
+
+    Game = Game or {} --so if something else made a "Game" table, we would save the previous table, and just add on to it
+    Game.Shutdown = function() Shell::RequestExit() end
+    Game.SetPaused = function(paused) GameDetails::SetPaused(paused) end --where paused is a bool
+    Game.SetDifficulty = function(difficulty) GameDetails::SetDifficulty(difficulty) end --difficulty is a value from Game.difficulty
+    Game.SetDefenderColour = function(colour) GameDetails::SetDefenderColour(colour) end --colour is of type Colourb
+    Game.SubmitHighScore = function() HighScores::SubmitScore(stuff from GameDetails) end
+    Game.SetHighScoreName = function(name) HighScore::SubmitName(name) end -- name is a string
+    Game.difficulty = { "HARD" = GameDetails::HARD, "EASY" = GameDetails::EASY }
+*/
+
+struct lua_State;
+class Game;
+class LuaInterface
+{
+public:
+    static void Initialise(lua_State* L);
+    static void InitGame(lua_State* L);
+};
+
+#endif

+ 84 - 0
Samples/luainvaders/src/Mothership.cpp

@@ -0,0 +1,84 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "Mothership.h"
+#include <Rocket/Core/Math.h>
+#include "Shell.h"
+#include "Game.h"
+#include "Sprite.h"
+
+const int SPRITE_WIDTH = 64;
+const int SPRITE_HEIGHT = 28;
+
+const float APPEARANCE_PROBABILITY = 0.001f;
+const float UPDATE_FREQ = 0.025f;
+const float MOVEMENT_SPEED = 5;
+
+Mothership::Mothership(Game* game, int index) : Invader(game, Invader::MOTHERSHIP, index)
+{
+	// Start off dead, and set up our position
+	state = DEAD;
+	update_frame_start = 0;
+	position = Rocket::Core::Vector2f(-SPRITE_WIDTH, 64.0f);
+}
+
+Mothership::~Mothership()
+{
+}
+
+void Mothership::Update()
+{
+	// Generic Invader update
+	Invader::Update();
+
+	if (Shell::GetElapsedTime() - update_frame_start < UPDATE_FREQ)
+		return;
+
+	// We're alive, keep moving!
+	if (state == ALIVE)
+	{
+		position.x += (direction * MOVEMENT_SPEED);
+
+		if ((direction < 0.0f && position.x < -SPRITE_WIDTH)
+			|| (direction > 0.0f && position.x > game->GetWindowDimensions().x))
+			state = DEAD;
+
+		update_frame_start = Shell::GetElapsedTime();
+	}
+	// Determine if we should come out of hiding
+	else if (Rocket::Core::Math::RandomReal(1.0f) < APPEARANCE_PROBABILITY)
+	{
+		direction = Rocket::Core::Math::RandomReal(1.0f) < 0.5 ? -1.0f : 1.0f;
+
+		if (direction < 0)
+			position.x = game->GetWindowDimensions().x + SPRITE_WIDTH;
+		else
+			position.x = -SPRITE_WIDTH;
+
+		state = ALIVE;
+	}
+}

+ 53 - 0
Samples/luainvaders/src/Mothership.h

@@ -0,0 +1,53 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSMOTHERSHIP_H
+#define ROCKETINVADERSMOTHERSHIP_H
+
+#include "Invader.h"
+
+/**
+ */
+
+class Mothership : public Invader
+{
+public:
+	Mothership(Game* game, int index);
+	~Mothership();
+
+	/// Update the mothership
+	virtual void Update();	
+
+private:
+	// Time of the last update
+	float update_frame_start;
+
+	// Direction mothership is flying in
+	float direction;
+};
+
+#endif

+ 188 - 0
Samples/luainvaders/src/Shield.cpp

@@ -0,0 +1,188 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "Shield.h"
+#include <Rocket/Core/Math.h>
+#include <ShellOpenGL.h>
+#include "Game.h"
+#include "GameDetails.h"
+#include "Sprite.h"
+
+const int MAX_HEALTH = 4;
+
+Shield::Shield(Game* _game, ShieldType _type) : position(0,0)
+{
+	game = _game;
+	type = _type;
+	health = MAX_HEALTH;
+
+	InitialiseCells();
+}
+
+Shield::~Shield()
+{
+}
+
+void Shield::InitialiseCells()
+{
+	if (type == REGULAR || type == TOP_LEFT || type == TOP_RIGHT)
+	{
+		for (int i = 0; i < NUM_SHIELD_CELLS; i++)
+		{
+			for (int j = 0; j < NUM_SHIELD_CELLS; j++)
+			{
+				shield_cells[i][j] = ON;
+			}
+		}
+
+		// Take the bites out of the cells if they're a corner cell:
+		if (type == TOP_LEFT)
+		{
+			for (int x = 0; x < NUM_SHIELD_CELLS - 1; x++)
+			{
+				for (int y = 0; y < (NUM_SHIELD_CELLS - 1) - x; y++)
+					shield_cells[x][y] = OFF;
+			}
+		}
+
+		else if (type == TOP_RIGHT)
+		{
+			for (int x = 0; x < NUM_SHIELD_CELLS - 1; x++)
+			{
+				for (int y = 0; y < (NUM_SHIELD_CELLS - 1) - x; y++)
+					shield_cells[(NUM_SHIELD_CELLS - 1) - x][y] = OFF;
+			}
+		}
+	}
+	else
+	{
+		for (int i = 0; i < NUM_SHIELD_CELLS; i++)
+		{
+			for (int j = 0; j < NUM_SHIELD_CELLS; j++)
+			{
+				shield_cells[i][j] = OFF;
+			}
+		}
+
+		if (type == BOTTOM_LEFT)
+		{
+			for (int x = 0; x < NUM_SHIELD_CELLS - 1; x++)
+			{
+				for (int y = 0; y < (NUM_SHIELD_CELLS - 1) - x; y++)
+					shield_cells[(NUM_SHIELD_CELLS - 1) - x][y] = ON;
+			}
+		}
+
+		else if (type == BOTTOM_RIGHT)
+		{
+			for (int x = 0; x < NUM_SHIELD_CELLS - 1; x++)
+			{
+				for (int y = 0; y < (NUM_SHIELD_CELLS - 1) - x; y++)
+					shield_cells[x][y] = ON;
+			}
+		}
+	}
+}
+
+void Shield::SetPosition(const Rocket::Core::Vector2f& _position)
+{
+	position = _position;
+}
+
+const Rocket::Core::Vector2f& Shield::GetPosition() const
+{
+	return position;
+}
+
+void Shield::Render()
+{
+	if (health > 0)
+	{
+		glPointSize((GLfloat) PIXEL_SIZE);
+		glDisable(GL_TEXTURE_2D);
+		glColor4ubv(GameDetails::GetDefenderColour());
+
+		glBegin(GL_POINTS);
+
+		for (int i = 0; i < NUM_SHIELD_CELLS; i++)
+		{
+			for (int j = 0; j < NUM_SHIELD_CELLS; j++)
+			{
+				if (shield_cells[i][j] == ON)
+				{
+					Rocket::Core::Vector2f cell_position = position + Rocket::Core::Vector2f((float) (PIXEL_SIZE * i), (float) (PIXEL_SIZE * j));
+					glVertex2f(cell_position.x, cell_position.y);
+				}
+			}
+		}
+
+		glEnd();
+
+		glEnable(GL_TEXTURE_2D);
+	}
+}
+
+bool Shield::CheckHit(const Rocket::Core::Vector2f& check_position)
+{
+	float sprite_size = PIXEL_SIZE * NUM_SHIELD_CELLS;
+
+	// If we're alive and the position is within our bounds, set ourselves
+	// as exploding and return a valid hit
+	if (health > 0
+		&& check_position.x >= position.x
+		&& check_position.x <= position.x + sprite_size
+		&& check_position.y >= position.y
+		&& check_position.y <= position.y + sprite_size)
+	{
+		// Take damage.
+		SustainDamage();
+
+		return true;
+	}
+
+	return false;
+}
+
+void Shield::SustainDamage()
+{
+	health--;
+
+	if (health > 0)
+	{
+		int num_shields_to_lose = (NUM_SHIELD_CELLS * NUM_SHIELD_CELLS) / MAX_HEALTH;
+		while (num_shields_to_lose > 0)
+		{
+			int x = Rocket::Core::Math::RandomInteger(NUM_SHIELD_CELLS);
+			int y = Rocket::Core::Math::RandomInteger(NUM_SHIELD_CELLS);
+			if (shield_cells[x][y] != DESTROYED)
+			{
+				shield_cells[x][y] = DESTROYED;
+				num_shields_to_lose--;
+			}
+		}
+	}
+}

+ 90 - 0
Samples/luainvaders/src/Shield.h

@@ -0,0 +1,90 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSSHIELD_H
+#define ROCKETINVADERSSHIELD_H
+
+#include <Rocket/Core/Types.h>
+
+class Game;
+
+const int NUM_SHIELD_CELLS = 6;
+const int PIXEL_SIZE = 4;
+
+/**
+	A shield, protecting the player.
+
+	@author Robert Curry
+ */
+
+class Shield
+{
+public:
+	enum ShieldType { REGULAR, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT };
+
+	/// Construct the invader
+	Shield(Game* game, ShieldType type);
+	~Shield();
+
+	/// Sets up which cells are on and off, based on the type.
+	void InitialiseCells();
+
+	/// Set the shield's screen position
+	/// @param position Position in screen space
+	void SetPosition(const Rocket::Core::Vector2f& position);
+	/// Get the current shield position
+	/// @returns The shield's position in screen space
+	const Rocket::Core::Vector2f& GetPosition() const;
+
+	/// Render the shield.
+	void Render();
+
+	/// Returns true if the position hits the shield
+	/// If a hit is detected, will degrade the shield.
+	/// @param position Position to do the hit check at
+	/// @returns If the shield was hit
+	bool CheckHit(const Rocket::Core::Vector2f& position);
+
+protected:
+	void SustainDamage();
+
+	// Game this shield is in
+	Game* game;
+
+	// The invader type we represent
+	ShieldType type;
+	// The current position in screen space of the shield
+	Rocket::Core::Vector2f position;
+
+	// Our current state - starts at 4, degrades once per hit.
+	int health;
+
+	enum ShieldCellState { ON, OFF, DESTROYED };
+	ShieldCellState shield_cells[NUM_SHIELD_CELLS][NUM_SHIELD_CELLS];
+};
+
+#endif

+ 52 - 0
Samples/luainvaders/src/Sprite.cpp

@@ -0,0 +1,52 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "Sprite.h"
+#include <ShellOpenGL.h>
+
+Sprite::Sprite(const Rocket::Core::Vector2f& dimensions, const Rocket::Core::Vector2f& top_left_texcoord, const Rocket::Core::Vector2f& bottom_right_texcoord) : dimensions(dimensions), top_left_texcoord(top_left_texcoord), bottom_right_texcoord(bottom_right_texcoord)
+{
+}
+
+Sprite::~Sprite()
+{
+}
+
+void Sprite::Render(const Rocket::Core::Vector2f& position)
+{
+	glTexCoord2f(top_left_texcoord.x, top_left_texcoord.y);
+	glVertex2f(position.x, position.y);
+
+	glTexCoord2f(top_left_texcoord.x, bottom_right_texcoord.y);
+	glVertex2f(position.x, position.y + dimensions.y);
+
+	glTexCoord2f(bottom_right_texcoord.x, bottom_right_texcoord.y);
+	glVertex2f(position.x + dimensions.x, position.y + dimensions.y);
+
+	glTexCoord2f(bottom_right_texcoord.x, top_left_texcoord.y);
+	glVertex2f(position.x + dimensions.x, position.y);
+}

+ 50 - 0
Samples/luainvaders/src/Sprite.h

@@ -0,0 +1,50 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef ROCKETINVADERSSPRITE_H
+#define ROCKETINVADERSSPRITE_H
+
+#include <Rocket/Core/Types.h>
+
+/**
+	@author Peter Curry
+ */
+
+class Sprite
+{
+public:
+	Sprite(const Rocket::Core::Vector2f& dimensions, const Rocket::Core::Vector2f& top_left_texcoord, const Rocket::Core::Vector2f& bottom_right_texcoord);
+	~Sprite();
+
+	void Render(const Rocket::Core::Vector2f& position);
+
+	Rocket::Core::Vector2f dimensions;
+	Rocket::Core::Vector2f top_left_texcoord;
+	Rocket::Core::Vector2f bottom_right_texcoord;
+};
+
+#endif

+ 198 - 0
Samples/luainvaders/src/main.cpp

@@ -0,0 +1,198 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#define _WIN32_WINNT 0x0500
+#include <Rocket/Core.h>
+#include <Rocket/Controls.h>
+#include <Rocket/Debugger.h>
+
+#include <Input.h>
+#include <Shell.h>
+#include "DecoratorInstancerDefender.h"
+#include "DecoratorInstancerStarfield.h"
+#include "ElementGame.h"
+#include "HighScores.h"
+#include <Rocket/Core/Lua/Interpreter.h>
+#include <Rocket/Controls/Lua/Controls.h>
+#include "LuaInterface.h"
+
+Rocket::Core::Context* context = NULL;
+
+void DoAllocConsole();
+
+void GameLoop()
+{
+	context->Update();
+
+	glClear(GL_COLOR_BUFFER_BIT);
+	context->Render();
+	Shell::FlipBuffers();
+}
+
+#if defined ROCKET_PLATFORM_WIN32
+#include <windows.h>
+int APIENTRY WinMain(HINSTANCE, HINSTANCE, char*, int)
+#else
+int main(int, char**)
+#endif
+{
+	#ifdef ROCKET_PLATFORM_MACOSX
+	#define APP_PATH "../"
+	#define ROCKET_PATH "../../bin/"
+	#else
+	#define APP_PATH "../Samples/luainvaders/"
+	#define ROCKET_PATH "."
+	#endif
+
+	#ifdef ROCKET_PLATFORM_WIN32
+	DoAllocConsole();
+	#endif
+
+	// Generic OS initialisation, creates a window and attaches OpenGL.
+	if (!Shell::Initialise("../Samples/luainvaders/") ||
+		!Shell::OpenWindow("Rocket Invaders from Mars (Lua Powered)", true))
+	{
+		Shell::Shutdown();
+		return -1;
+	}
+
+	// Rocket initialisation.
+	ShellRenderInterfaceOpenGL opengl_renderer;
+	Rocket::Core::SetRenderInterface(&opengl_renderer);
+	opengl_renderer.SetViewport(1024,768);
+
+	ShellSystemInterface system_interface;
+	Rocket::Core::SetSystemInterface(&system_interface);
+
+	Rocket::Core::Initialise();
+	// Initialise the Rocket Controls library.
+	Rocket::Controls::Initialise();
+
+	// Initialise the Lua interface
+    Rocket::Core::Lua::Interpreter::Initialise();
+    Rocket::Controls::Lua::RegisterTypes(Rocket::Core::Lua::Interpreter::GetLuaState());
+
+	// Create the main Rocket context and set it on the shell's input layer.
+	context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));
+	if (context == NULL)
+	{
+		Rocket::Core::Shutdown();
+		Shell::Shutdown();
+		return -1;
+	}
+
+	Rocket::Debugger::Initialise(context);
+	Input::SetContext(context);
+
+	// Load the font faces required for Invaders.
+	Shell::LoadFonts("../assets/");
+
+	// Register Invader's custom decorator instancers.
+	Rocket::Core::DecoratorInstancer* decorator_instancer = new DecoratorInstancerStarfield();
+	Rocket::Core::Factory::RegisterDecoratorInstancer("starfield", decorator_instancer);
+	decorator_instancer->RemoveReference();
+
+	decorator_instancer = new DecoratorInstancerDefender();
+	Rocket::Core::Factory::RegisterDecoratorInstancer("defender", decorator_instancer);
+	decorator_instancer->RemoveReference();	
+
+	// Construct the game singletons.
+	HighScores::Initialise();
+
+	// Fire off the startup script.
+    LuaInterface::Initialise(Rocket::Core::Lua::Interpreter::GetLuaState()); //the tables/functions defined in the samples
+    Rocket::Core::Lua::Interpreter::LoadFile(Rocket::Core::String(APP_PATH).Append("lua/start.lua"));
+
+	Shell::EventLoop(GameLoop);	
+
+	// Shutdown the Rocket contexts.	
+	context->RemoveReference();
+	
+	// Shutdown Lua  before we shut down Rocket.
+	Rocket::Core::Lua::Interpreter::Shutdown();
+
+	// Shut down the game singletons.
+	HighScores::Shutdown();
+
+	// Shutdown Rocket.
+	Rocket::Core::Shutdown();
+
+	Shell::CloseWindow();
+	Shell::Shutdown();
+
+	return 0;
+}
+
+#ifdef ROCKET_PLATFORM_WIN32
+
+#include <windows.h>
+#include <fcntl.h>
+#include <io.h>
+#include <process.h>
+
+void DoAllocConsole()
+{
+	static const WORD MAX_CONSOLE_LINES = 500;
+	int hConHandle;
+	long lStdHandle;
+	CONSOLE_SCREEN_BUFFER_INFO coninfo;
+	FILE *fp;
+
+	// allocate a console for this app
+	AllocConsole();
+
+	// set the screen buffer to be big enough to let us scroll text
+	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
+	coninfo.dwSize.Y = MAX_CONSOLE_LINES;
+	SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
+
+	// redirect unbuffered STDOUT to the console
+	lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
+	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
+	fp = _fdopen( hConHandle, "w" );
+
+	*stdout = *fp;
+	setvbuf( stdout, NULL, _IONBF, 0 );
+
+	// redirect unbuffered STDIN to the console
+	lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
+	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
+	fp = _fdopen( hConHandle, "r" );
+
+	*stdin = *fp;
+	setvbuf( stdin, NULL, _IONBF, 0 );
+
+	// redirect unbuffered STDERR to the console
+	lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
+	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
+	fp = _fdopen( hConHandle, "w" );
+	*stderr = *fp;
+
+	setvbuf( stderr, NULL, _IONBF, 0 );
+	ShowWindow(GetConsoleWindow(), SW_SHOW);
+}
+#endif

+ 72 - 0
Source/Controls/Lua/As.h

@@ -0,0 +1,72 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAAS_H
+#define ROCKETCONTROLSLUAAS_H
+/*
+    These are helper functions to fill up the Element.As table with types that are able to be casted
+*/
+
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Element.h>
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//Helper function for the controls, so that the types don't have to define individual functions themselves
+// to fill the Elements.As table
+template<typename ToType>
+int CastFromElementTo(lua_State* L)
+{
+    Rocket::Core::Element* ele = Rocket::Core::Lua::LuaType<Rocket::Core::Element>::check(L,1);
+    LUACHECKOBJ(ele);
+    Rocket::Core::Lua::LuaType<ToType>::push(L,(ToType*)ele,false);
+    return 1;
+}
+
+//Adds to the Element.As table the name of the type, and the function to use to cast
+template<typename T>
+void AddCastFunctionToElementAsTable(lua_State* L)
+{
+    int top = lua_gettop(L);
+    lua_getglobal(L,"Element");
+    lua_getfield(L,-1,"As");
+    if(!lua_isnoneornil(L,-1))
+    {
+        lua_pushcfunction(L,Rocket::Controls::Lua::CastFromElementTo<T>);
+        lua_setfield(L,-2,Rocket::Core::Lua::GetTClassName<T>());
+    }
+    lua_settop(L,top); //pop "As" and "Element"
+}
+
+}
+}
+}
+
+#endif

+ 81 - 0
Source/Controls/Lua/Controls.cpp

@@ -0,0 +1,81 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "precompiled.h"
+#include <Rocket/Controls/Lua/Controls.h>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/Interpreter.h>
+#include <Rocket/Core/Log.h>
+#include "SelectOptionsProxy.h"
+#include "DataFormatter.h"
+#include "DataSource.h"
+#include "ElementForm.h"
+#include "ElementFormControl.h"
+#include "ElementFormControlSelect.h"
+#include "ElementFormControlDataSelect.h"
+#include "ElementFormControlInput.h"
+#include "ElementFormControlTextArea.h"
+#include "ElementDataGrid.h"
+#include "ElementDataGridRow.h"
+#include "ElementTabSet.h"
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//This will define all of the types from RocketControls for Lua. There is not a
+//corresponding function for types of RocketCore, because they are defined automatically
+//when the Interpreter starts.
+void RegisterTypes(lua_State* L)
+{
+    if(Rocket::Core::Lua::Interpreter::GetLuaState() == NULL)
+    {
+        Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR,
+            "In Rocket::Controls::Lua::RegisterTypes: Tried to register the \'Controls\' types for Lua without first initializing the Interpreter.");
+        return;
+    }
+    LuaType<ElementForm>::Register(L);
+    LuaType<ElementFormControl>::Register(L);
+        //Inherits from ElementFormControl
+        LuaType<ElementFormControlSelect>::Register(L);
+            LuaType<ElementFormControlDataSelect>::Register(L);
+        LuaType<ElementFormControlInput>::Register(L);
+        LuaType<ElementFormControlTextArea>::Register(L);
+    LuaType<DataFormatter>::Register(L);
+    LuaType<DataSource>::Register(L);
+    LuaType<ElementDataGrid>::Register(L);
+    LuaType<ElementDataGridRow>::Register(L);
+    LuaType<ElementTabSet>::Register(L);
+    //proxy tables
+    LuaType<SelectOptionsProxy>::Register(L);
+}
+
+}
+}
+}

+ 121 - 0
Source/Controls/Lua/DataFormatter.cpp

@@ -0,0 +1,121 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "DataFormatter.h"
+
+
+using Rocket::Core::Log;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+//method
+int DataFormatternew(lua_State* L)
+{
+    DataFormatter* df;
+    int ref = LUA_NOREF;
+    int top = lua_gettop(L);
+    if(top == 0)
+        df = new DataFormatter();
+    else if (top > 0) //at least one element means at least a name
+    {
+        if(top > 1) //if a function as well
+        {
+            if(lua_type(L,2) != LUA_TFUNCTION)
+            {
+                Log::Message(Log::LT_ERROR, "Lua: In DataFormatter.new, the second argument MUST be a function (or not exist). You passed in a %s.", lua_typename(L,lua_type(L,2)));
+            }
+            else //if it is a function
+            {
+                LuaDataFormatter::PushDataFormatterFunctionTable(L);
+                lua_pushvalue(L,2); //re-push the function so it is on the top of the stack
+                ref = luaL_ref(L,-2);
+                lua_pop(L,1); //pop the function table
+            }
+        }
+        df = new DataFormatter(luaL_checkstring(L,1));
+        df->ref_FormatData = ref; //will either be valid or LUA_NOREF
+    }
+    LuaType<DataFormatter>::push(L,df,true);
+    return 1;
+}
+
+//setter
+int DataFormatterSetAttrFormatData(lua_State* L)
+{
+    DataFormatter* obj = LuaType<DataFormatter>::check(L,1);
+    LUACHECKOBJ(obj);
+    int ref = LUA_NOREF;
+    if(lua_type(L,2) != LUA_TFUNCTION)
+    {
+        Log::Message(Log::LT_ERROR, "Lua: Setting DataFormatter.FormatData, the value must be a function. You passed in a %s.", lua_typename(L,lua_type(L,2)));
+    }
+    else //if it is a function
+    {
+        LuaDataFormatter::PushDataFormatterFunctionTable(L);
+        lua_pushvalue(L,2); //re-push the function so it is on the top of the stack
+        ref = luaL_ref(L,-2);
+        lua_pop(L,1); //pop the function table
+    }
+    obj->ref_FormatData = ref;
+    return 0;
+}
+
+Rocket::Core::Lua::RegType<DataFormatter> DataFormatterMethods[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg DataFormatterGetters[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg DataFormatterSetters[] =
+{
+    LUASETTER(DataFormatter,FormatData)
+    { NULL, NULL },
+};
+
+}
+}
+}
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+using Rocket::Controls::Lua::DataFormatter;
+template<> void ExtraInit<DataFormatter>(lua_State* L, int metatable_index)
+{
+    lua_pushcfunction(L,Rocket::Controls::Lua::DataFormatternew);
+    lua_setfield(L,metatable_index-1,"new");
+    return;
+}
+LUACONTROLSTYPEDEFINE(DataFormatter,false)
+}
+}
+}

+ 58 - 0
Source/Controls/Lua/DataFormatter.h

@@ -0,0 +1,58 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUADATAFORMATTER_H
+#define ROCKETCONTROLSLUADATAFORMATTER_H
+
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include "LuaDataFormatter.h"
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+typedef LuaDataFormatter DataFormatter;
+//method
+int DataFormatternew(lua_State* L);
+
+//setter
+int DataFormatterSetAttrFormatData(lua_State* L);
+
+extern Rocket::Core::Lua::RegType<DataFormatter> DataFormatterMethods[];
+extern luaL_Reg DataFormatterGetters[];
+extern luaL_Reg DataFormatterSetters[];
+}
+}
+}
+//for DataFormatter.new
+namespace Rocket { namespace Core { namespace Lua {
+template<> void ExtraInit<Rocket::Controls::Lua::DataFormatter>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::Lua::DataFormatter)
+}}}
+#endif

+ 151 - 0
Source/Controls/Lua/DataSource.cpp

@@ -0,0 +1,151 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "DataSource.h"
+#include <Rocket/Core/Log.h>
+
+using Rocket::Core::Log;
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+typedef LuaDataSource DataSource;
+
+int DataSourcenew(lua_State* L)
+{
+    const char* name = luaL_checkstring(L,1);
+    LuaDataSource* ds = new LuaDataSource(name);
+    LuaType<DataSource>::push(L,ds,true);
+    return 1;
+}
+
+int DataSourceNotifyRowAdd(lua_State* L, DataSource* obj)
+{
+    LUACHECKOBJ(obj);
+    const char* table_name = luaL_checkstring(L,1);
+    int first_row_added = luaL_checkint(L,2);
+    int num_rows_added = luaL_checkint(L,3);
+    obj->NotifyRowAdd(table_name,first_row_added,num_rows_added);
+    return 0;
+}
+
+int DataSourceNotifyRowRemove(lua_State* L, DataSource* obj)
+{
+    LUACHECKOBJ(obj);
+    const char* table_name = luaL_checkstring(L,1);
+    int first_row_removed = luaL_checkint(L,2);
+    int num_rows_removed = luaL_checkint(L,3);
+    obj->NotifyRowRemove(table_name,first_row_removed,num_rows_removed);
+    return 0;
+}
+
+int DataSourceNotifyRowChange(lua_State* L, DataSource* obj)
+{
+    LUACHECKOBJ(obj);
+    const char* table_name = luaL_checkstring(L,1);
+    if(lua_gettop(L) < 2)
+    {
+        obj->NotifyRowChange(table_name);
+    }
+    else
+    {
+        int first_row_changed = luaL_checkint(L,2);
+        int num_rows_changed = luaL_checkint(L,3);
+        obj->NotifyRowChange(table_name,first_row_changed,num_rows_changed);
+    }
+    return 0;
+}
+
+int DataSourceSetAttrGetNumRows(lua_State* L)
+{
+    DataSource* obj = LuaType<DataSource>::check(L,1);
+    LUACHECKOBJ(obj);
+    if(lua_type(L,2) == LUA_TFUNCTION)
+    {
+        lua_pushvalue(L,2); //copy of the function, so it is for sure at the top of the stack
+        obj->getNumRowsRef = luaL_ref(L, LUA_REGISTRYINDEX);
+    }
+    else
+        Log::Message(Log::LT_WARNING, "Lua: Must assign DataSource.GetNumRows as a function, value received was of %s type", lua_typename(L,2));
+    return 0;
+}
+
+int DataSourceSetAttrGetRow(lua_State* L)
+{
+    DataSource* obj = LuaType<DataSource>::check(L,1);
+    LUACHECKOBJ(obj);
+    if(lua_type(L,2) == LUA_TFUNCTION)
+    {
+        lua_pushvalue(L,2); //copy of the functions, so it is for sure at the top of the stack
+        obj->getRowRef = luaL_ref(L, LUA_REGISTRYINDEX);
+    }
+    else
+        Log::Message(Log::LT_WARNING, "Lua: Must assign DataSource.GetRow as a function, value received was of %s type", lua_typename(L,2));
+    return 0;
+}
+
+
+Rocket::Core::Lua::RegType<DataSource> DataSourceMethods[] =
+{
+    LUAMETHOD(DataSource,NotifyRowAdd)
+    LUAMETHOD(DataSource,NotifyRowRemove)
+    LUAMETHOD(DataSource,NotifyRowChange)
+    { NULL, NULL },
+};
+
+luaL_Reg DataSourceGetters[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg DataSourceSetters[] =
+{
+    LUASETTER(DataSource,GetNumRows)
+    LUASETTER(DataSource,GetRow)
+    { NULL, NULL },
+};
+
+
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Rocket::Controls::Lua::LuaDataSource>(lua_State* L, int metatable_index) 
+{ 
+    lua_pushcfunction(L,Rocket::Controls::Lua::DataSourcenew);
+    lua_setfield(L,metatable_index-1,"new");
+    return;
+}
+using Rocket::Controls::Lua::DataSource;
+LUACONTROLSTYPEDEFINE(DataSource,false)
+}
+}
+}

+ 63 - 0
Source/Controls/Lua/DataSource.h

@@ -0,0 +1,63 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUADATASOURCE_H
+#define ROCKETCONTROLSLUADATASOURCE_H
+
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include "LuaDataSource.h"
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+typedef LuaDataSource DataSource;
+
+int DataSourcenew(lua_State* L);
+
+int DataSourceNotifyRowAdd(lua_State* L, DataSource* obj);
+int DataSourceNotifyRowRemove(lua_State* L, DataSource* obj);
+int DataSourceNotifyRowChange(lua_State* L, DataSource* obj);
+
+int DataSourceSetAttrGetNumRows(lua_State* L);
+int DataSourceSetAttrGetRow(lua_State* L);
+
+extern Rocket::Core::Lua::RegType<DataSource> DataSourceMethods[];
+extern luaL_Reg DataSourceGetters[];
+extern luaL_Reg DataSourceSetters[];
+
+
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+template<> void ExtraInit<Rocket::Controls::Lua::LuaDataSource>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::Lua::DataSource)
+}}}
+#endif

+ 119 - 0
Source/Controls/Lua/ElementDataGrid.cpp

@@ -0,0 +1,119 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementDataGrid.h"
+#include <Rocket/Core/Element.h>
+#include <Rocket/Controls/ElementDataGridRow.h>
+#include <Rocket/Core/Lua/Utilities.h>
+
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+
+//methods
+int ElementDataGridAddColumn(lua_State* L, ElementDataGrid* obj)
+{
+    LUACHECKOBJ(obj);
+    const char* fields = luaL_checkstring(L,1);
+    const char* formatter = luaL_checkstring(L,2);
+    float width = (float)luaL_checknumber(L,3);
+    const char* rml = luaL_checkstring(L,4);
+
+    obj->AddColumn(fields,formatter,width,rml);
+    return 0;
+}
+
+int ElementDataGridSetDataSource(lua_State* L, ElementDataGrid* obj)
+{
+    LUACHECKOBJ(obj);
+    const char* source = luaL_checkstring(L,1);
+    
+    obj->SetDataSource(source);
+    return 0;
+}
+
+
+//getter
+int ElementDataGridGetAttrrows(lua_State* L)
+{
+    ElementDataGrid* obj = LuaType<ElementDataGrid>::check(L,1);
+    LUACHECKOBJ(obj);
+
+    lua_newtable(L);
+    int tbl = lua_gettop(L);
+    int numrows = obj->GetNumRows();
+    ElementDataGridRow* row;
+    for(int i = 0; i < numrows; i++)
+    {
+        row = obj->GetRow(i);
+        LuaType<ElementDataGridRow>::push(L,row,false);
+        lua_rawseti(L,tbl,i);
+    }
+    return 1;
+}
+
+
+
+Rocket::Core::Lua::RegType<ElementDataGrid> ElementDataGridMethods[] =
+{
+    LUAMETHOD(ElementDataGrid,AddColumn)
+    LUAMETHOD(ElementDataGrid,SetDataSource)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementDataGridGetters[] =
+{
+    LUAGETTER(ElementDataGrid,rows)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementDataGridSetters[] =
+{
+    { NULL, NULL },
+};
+
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Rocket::Controls::ElementDataGrid>(lua_State* L, int metatable_index)
+{
+    ExtraInit<Element>(L,metatable_index);
+    LuaType<Element>::_regfunctions(L,metatable_index,metatable_index-1);
+    AddTypeToElementAsTable<Rocket::Controls::ElementDataGrid>(L);
+}
+using Rocket::Controls::ElementDataGrid;
+LUACONTROLSTYPEDEFINE(ElementDataGrid,true)
+}
+}
+}

+ 62 - 0
Source/Controls/Lua/ElementDataGrid.h

@@ -0,0 +1,62 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAELEMENTDATAGRID_H
+#define ROCKETCONTROLSLUAELEMENTDATAGRID_H
+
+
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Controls/ElementDataGrid.h>
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//methods
+int ElementDataGridAddColumn(lua_State* L, ElementDataGrid* obj);
+int ElementDataGridSetDataSource(lua_State* L, ElementDataGrid* obj);
+
+//getter
+int ElementDataGridGetAttrrows(lua_State* L);
+
+
+extern Rocket::Core::Lua::RegType<ElementDataGrid> ElementDataGridMethods[];
+extern luaL_Reg ElementDataGridGetters[];
+extern luaL_Reg ElementDataGridSetters[];
+
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+//this will be used to "inherit" from Element
+template<> void ExtraInit<Rocket::Controls::ElementDataGrid>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::ElementDataGrid)
+}}}
+#endif

+ 133 - 0
Source/Controls/Lua/ElementDataGridRow.cpp

@@ -0,0 +1,133 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementDataGridRow.h"
+#include <Rocket/Controls/ElementDataGrid.h>
+#include <Rocket/Core/Lua/Utilities.h>
+
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+
+//getters
+int ElementDataGridRowGetAttrrow_expanded(lua_State* L)
+{
+    ElementDataGridRow* obj = LuaType<ElementDataGridRow>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushboolean(L,obj->IsRowExpanded());
+    return 1;
+}
+
+int ElementDataGridRowGetAttrparent_relative_index(lua_State* L)
+{
+    ElementDataGridRow* obj = LuaType<ElementDataGridRow>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetParentRelativeIndex());
+    return 1;
+}
+
+int ElementDataGridRowGetAttrtable_relative_index(lua_State* L)
+{
+    ElementDataGridRow* obj = LuaType<ElementDataGridRow>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetTableRelativeIndex());
+    return 1;
+}
+
+int ElementDataGridRowGetAttrparent_row(lua_State* L)
+{
+    ElementDataGridRow* obj = LuaType<ElementDataGridRow>::check(L,1);
+    LUACHECKOBJ(obj);
+    LuaType<ElementDataGridRow>::push(L,obj->GetParentRow(),false);
+    return 1;
+}
+
+int ElementDataGridRowGetAttrparent_grid(lua_State* L)
+{
+    ElementDataGridRow* obj = LuaType<ElementDataGridRow>::check(L,1);
+    LUACHECKOBJ(obj);
+    LuaType<ElementDataGrid>::push(L,obj->GetParentGrid(),false);
+    return 1;
+}
+
+
+//setter
+int ElementDataGridRowSetAttrrow_expanded(lua_State* L)
+{
+    ElementDataGridRow* obj = LuaType<ElementDataGridRow>::check(L,1);
+    LUACHECKOBJ(obj);
+    bool expanded = CHECK_BOOL(L,2);
+    if(expanded)
+        obj->ExpandRow();
+    else
+        obj->CollapseRow();
+    return 0;
+}
+
+
+
+Rocket::Core::Lua::RegType<ElementDataGridRow> ElementDataGridRowMethods[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg ElementDataGridRowGetters[] =
+{
+    LUAGETTER(ElementDataGridRow,row_expanded)
+    LUAGETTER(ElementDataGridRow,parent_relative_index)
+    LUAGETTER(ElementDataGridRow,table_relative_index)
+    LUAGETTER(ElementDataGridRow,parent_row)
+    LUAGETTER(ElementDataGridRow,parent_grid)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementDataGridRowSetters[] =
+{
+    LUASETTER(ElementDataGridRow,row_expanded)
+    { NULL, NULL },
+};
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Rocket::Controls::ElementDataGridRow>(lua_State* L, int metatable_index)
+{
+    ExtraInit<Element>(L,metatable_index);
+    LuaType<Element>::_regfunctions(L,metatable_index,metatable_index-1);
+    AddTypeToElementAsTable<Rocket::Controls::ElementDataGridRow>(L);
+}
+using Rocket::Controls::ElementDataGridRow;
+LUACONTROLSTYPEDEFINE(ElementDataGridRow,true)
+}
+}
+}

+ 66 - 0
Source/Controls/Lua/ElementDataGridRow.h

@@ -0,0 +1,66 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAELEMENTDATAGRIDROW_H
+#define ROCKETCONTROLSLUAELEMENTDATAGRIDROW_H
+
+
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Controls/ElementDataGridRow.h>
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//getters
+int ElementDataGridRowGetAttrrow_expanded(lua_State* L);
+int ElementDataGridRowGetAttrparent_relative_index(lua_State* L);
+int ElementDataGridRowGetAttrtable_relative_index(lua_State* L);
+int ElementDataGridRowGetAttrparent_row(lua_State* L);
+int ElementDataGridRowGetAttrparent_grid(lua_State* L);
+
+//setter
+int ElementDataGridRowSetAttrrow_expanded(lua_State* L);
+
+
+extern Rocket::Core::Lua::RegType<ElementDataGridRow> ElementDataGridRowMethods[];
+extern luaL_Reg ElementDataGridRowGetters[];
+extern luaL_Reg ElementDataGridRowSetters[];
+
+
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+//this will be used to "inherit" from Element
+template<> void ExtraInit<Rocket::Controls::ElementDataGridRow>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::ElementDataGridRow)
+}}}
+#endif

+ 88 - 0
Source/Controls/Lua/ElementForm.cpp

@@ -0,0 +1,88 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementForm.h"
+#include <Rocket/Core/Element.h>
+#include <Rocket/Controls/ElementForm.h>
+#include <Rocket/Core/Lua/Utilities.h>
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//method
+int ElementFormSubmit(lua_State* L, ElementForm* obj)
+{
+    int top = lua_gettop(L);
+    const char* name = "";
+    const char* value = "";
+    if(top > 0)
+    {
+        name = luaL_checkstring(L,1);
+        if(top > 1)
+            value = luaL_checkstring(L,2);
+    }
+    obj->Submit(name,value);
+    return 0;
+}
+
+Rocket::Core::Lua::RegType<ElementForm> ElementFormMethods[] =
+{
+    LUAMETHOD(ElementForm,Submit)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormGetters[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormSetters[] =
+{
+    { NULL, NULL },
+};
+
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Rocket::Controls::ElementForm>(lua_State* L, int metatable_index)
+{
+    //inherit from Element
+    ExtraInit<Element>(L,metatable_index);
+    LuaType<Element>::_regfunctions(L,metatable_index,metatable_index-1);
+    AddTypeToElementAsTable<Rocket::Controls::ElementForm>(L);
+}
+using Rocket::Controls::ElementForm;
+LUACONTROLSTYPEDEFINE(ElementForm,true)
+}
+}
+}

+ 56 - 0
Source/Controls/Lua/ElementForm.h

@@ -0,0 +1,56 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAELEMENTFORM_H
+#define ROCKETCONTROLSLUAELEMENTFORM_H
+
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Controls/ElementForm.h>
+
+using Rocket::Core::Lua::LuaType;
+
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//method
+int ElementFormSubmit(lua_State* L, ElementForm* obj);
+
+extern Rocket::Core::Lua::RegType<ElementForm> ElementFormMethods[];
+extern luaL_Reg ElementFormGetters[];
+extern luaL_Reg ElementFormSetters[];
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+//this will be used to "inherit" from Element
+template<> void ExtraInit<Rocket::Controls::ElementForm>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::ElementForm)
+}}}
+#endif

+ 131 - 0
Source/Controls/Lua/ElementFormControl.cpp

@@ -0,0 +1,131 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementFormControl.h"
+#include <Rocket/Controls/ElementFormControl.h>
+#include <Rocket/Core/Element.h>
+#include <Rocket/../../Source/Core/Lua/Element.h>
+#include <Rocket/Core/Lua/Utilities.h>
+
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//getters
+int ElementFormControlGetAttrdisabled(lua_State* L)
+{
+    ElementFormControl* efc = LuaType<ElementFormControl>::check(L,1);
+    LUACHECKOBJ(efc);
+    lua_pushboolean(L,efc->IsDisabled());
+    return 1;
+}
+
+int ElementFormControlGetAttrname(lua_State* L)
+{
+    ElementFormControl* efc = LuaType<ElementFormControl>::check(L,1);
+    LUACHECKOBJ(efc);
+    lua_pushstring(L,efc->GetName().CString());
+    return 1;
+}
+
+int ElementFormControlGetAttrvalue(lua_State* L)
+{
+    ElementFormControl* efc = LuaType<ElementFormControl>::check(L,1);
+    LUACHECKOBJ(efc);
+    lua_pushstring(L,efc->GetValue().CString());
+    return 1;
+}
+
+
+//setters
+int ElementFormControlSetAttrdisabled(lua_State* L)
+{
+    ElementFormControl* efc = LuaType<ElementFormControl>::check(L,1);
+    LUACHECKOBJ(efc);
+    efc->SetDisabled(CHECK_BOOL(L,2));
+    return 0;
+}
+
+int ElementFormControlSetAttrname(lua_State* L)
+{
+    ElementFormControl* efc = LuaType<ElementFormControl>::check(L,1);
+    LUACHECKOBJ(efc);
+    const char* name = luaL_checkstring(L,2);
+    efc->SetName(name);
+    return 0;
+}
+
+int ElementFormControlSetAttrvalue(lua_State* L)
+{
+    ElementFormControl* efc = LuaType<ElementFormControl>::check(L,1);
+    LUACHECKOBJ(efc);
+    const char* value = luaL_checkstring(L,2);
+    efc->SetValue(value);
+    return 0;
+}
+
+
+Rocket::Core::Lua::RegType<ElementFormControl> ElementFormControlMethods[] = 
+{
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormControlGetters[] = 
+{
+    LUAGETTER(ElementFormControl,disabled)
+    LUAGETTER(ElementFormControl,name)
+    LUAGETTER(ElementFormControl,value)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormControlSetters[] = 
+{
+    LUASETTER(ElementFormControl,disabled)
+    LUASETTER(ElementFormControl,name)
+    LUASETTER(ElementFormControl,value)
+    { NULL, NULL },
+};
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Rocket::Controls::ElementFormControl>(lua_State* L, int metatable_index)
+{
+    ExtraInit<Element>(L,metatable_index);
+    LuaType<Element>::_regfunctions(L,metatable_index,metatable_index-1);
+    AddTypeToElementAsTable<Rocket::Controls::ElementFormControl>(L);
+}
+using Rocket::Controls::ElementFormControl;
+LUACONTROLSTYPEDEFINE(ElementFormControl,true)
+}
+}
+}

+ 62 - 0
Source/Controls/Lua/ElementFormControl.h

@@ -0,0 +1,62 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAELEMENTFORMCONTROL_H
+#define ROCKETCONTROLSLUAELEMENTFORMCONTROL_H
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Controls/ElementFormControl.h>
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//getters
+int ElementFormControlGetAttrdisabled(lua_State* L);
+int ElementFormControlGetAttrname(lua_State* L);
+int ElementFormControlGetAttrvalue(lua_State* L);
+
+//setters
+int ElementFormControlSetAttrdisabled(lua_State* L);
+int ElementFormControlSetAttrname(lua_State* L);
+int ElementFormControlSetAttrvalue(lua_State* L);
+
+extern Rocket::Core::Lua::RegType<ElementFormControl> ElementFormControlMethods[];
+extern luaL_Reg ElementFormControlGetters[];
+extern luaL_Reg ElementFormControlSetters[];
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+template<> void ExtraInit<Rocket::Controls::ElementFormControl>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::ElementFormControl)
+}}}
+#endif
+

+ 82 - 0
Source/Controls/Lua/ElementFormControlDataSelect.cpp

@@ -0,0 +1,82 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementFormControlDataSelect.h"
+#include <Rocket/Controls/ElementFormControlSelect.h>
+#include "ElementFormControlSelect.h"
+#include <Rocket/Core/Lua/Utilities.h>
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//method
+int ElementFormControlDataSelectSetDataSource(lua_State* L, ElementFormControlDataSelect* obj)
+{
+    const char* source = luaL_checkstring(L,1);
+    obj->SetDataSource(source);
+    return 0;
+}
+
+Rocket::Core::Lua::RegType<ElementFormControlDataSelect> ElementFormControlDataSelectMethods[] =
+{
+    LUAMETHOD(ElementFormControlDataSelect,SetDataSource)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormControlDataSelectGetters[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormControlDataSelectSetters[] =
+{
+    { NULL, NULL },
+};
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+//inherits from ElementFormControl which inherits from Element
+template<> void ExtraInit<Rocket::Controls::ElementFormControlDataSelect>(lua_State* L, int metatable_index)
+{
+    //do whatever ElementFormControlSelect did as far as inheritance
+    ExtraInit<Rocket::Controls::ElementFormControlSelect>(L,metatable_index);
+    //then inherit from ElementFromControlSelect
+    LuaType<Rocket::Controls::ElementFormControlSelect>::_regfunctions(L,metatable_index,metatable_index-1);
+    AddTypeToElementAsTable<Rocket::Controls::ElementFormControlDataSelect>(L);
+}
+
+using Rocket::Controls::ElementFormControlDataSelect;
+LUACONTROLSTYPEDEFINE(ElementFormControlDataSelect,true)
+}
+}
+}

+ 55 - 0
Source/Controls/Lua/ElementFormControlDataSelect.h

@@ -0,0 +1,55 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAELEMENTFORMCONTROLDATASELECT_H
+#define ROCKETCONTROLSLUAELEMENTFORMCONTROLDATASELECT_H
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Controls/ElementFormControlDataSelect.h>
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//method
+int ElementFormControlDataSelectSetDataSource(lua_State* L, ElementFormControlDataSelect* obj);
+
+extern Rocket::Core::Lua::RegType<ElementFormControlDataSelect> ElementFormControlDataSelectMethods[];
+extern luaL_Reg ElementFormControlDataSelectGetters[];
+extern luaL_Reg ElementFormControlDataSelectSetters[];
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+//inherits from ElementFormControl which inherits from Element
+template<> void ExtraInit<Rocket::Controls::ElementFormControlDataSelect>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::ElementFormControlDataSelect)
+}}}
+#endif

+ 191 - 0
Source/Controls/Lua/ElementFormControlInput.cpp

@@ -0,0 +1,191 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementFormControlInput.h"
+#include <Rocket/Controls/ElementFormControl.h>
+#include "ElementFormControl.h"
+#include <Rocket/Core/Lua/Utilities.h>
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+
+//getters
+int ElementFormControlInputGetAttrchecked(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushboolean(L,obj->HasAttribute("checked"));
+    return 1;
+}
+
+int ElementFormControlInputGetAttrmaxlength(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetAttribute<int>("maxlength",-1));
+    return 1;
+}
+
+int ElementFormControlInputGetAttrsize(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetAttribute<int>("size",20));
+    return 1;
+}
+
+int ElementFormControlInputGetAttrmax(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetAttribute<int>("max",100));
+    return 1;
+}
+
+int ElementFormControlInputGetAttrmin(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetAttribute<int>("min",0));
+    return 1;
+}
+
+int ElementFormControlInputGetAttrstep(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetAttribute<int>("step",1));
+    return 1;
+}
+
+
+//setters
+int ElementFormControlInputSetAttrchecked(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    bool checked = CHECK_BOOL(L,2);
+    if(checked)
+        obj->SetAttribute("checked",true);
+    else
+        obj->RemoveAttribute("checked");
+    return 0;
+}
+
+int ElementFormControlInputSetAttrmaxlength(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    int maxlength = luaL_checkint(L,2);
+    obj->SetAttribute("maxlength",maxlength);
+    return 0;
+}
+
+int ElementFormControlInputSetAttrsize(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    int size = luaL_checkint(L,2);
+    obj->SetAttribute("size",size);
+    return 0;
+}
+
+int ElementFormControlInputSetAttrmax(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    int max = luaL_checkint(L,2);
+    obj->SetAttribute("max",max);
+    return 0;
+}
+
+int ElementFormControlInputSetAttrmin(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    int min = luaL_checkint(L,2);
+    obj->SetAttribute("min",min);
+    return 0;
+}
+
+int ElementFormControlInputSetAttrstep(lua_State* L)
+{
+    ElementFormControlInput* obj = LuaType<ElementFormControlInput>::check(L,1);
+    LUACHECKOBJ(obj);
+    int step = luaL_checkint(L,2);
+    obj->SetAttribute("step",step);
+    return 0;
+}
+
+
+Rocket::Core::Lua::RegType<ElementFormControlInput> ElementFormControlInputMethods[] = 
+{
+    {NULL,NULL},
+};
+
+luaL_Reg ElementFormControlInputGetters[] = 
+{
+    LUAGETTER(ElementFormControlInput,checked)
+    LUAGETTER(ElementFormControlInput,maxlength)
+    LUAGETTER(ElementFormControlInput,size)
+    LUAGETTER(ElementFormControlInput,max)
+    LUAGETTER(ElementFormControlInput,min)
+    LUAGETTER(ElementFormControlInput,step)
+    {NULL,NULL},
+};
+
+luaL_Reg ElementFormControlInputSetters[] = 
+{
+    LUASETTER(ElementFormControlInput,checked)
+    LUASETTER(ElementFormControlInput,maxlength)
+    LUASETTER(ElementFormControlInput,size)
+    LUASETTER(ElementFormControlInput,max)
+    LUASETTER(ElementFormControlInput,min)
+    LUASETTER(ElementFormControlInput,step)
+    {NULL,NULL},
+};
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Rocket::Controls::ElementFormControlInput>(lua_State* L, int metatable_index)
+{
+    ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
+    LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
+    AddTypeToElementAsTable<Rocket::Controls::ElementFormControlInput>(L);
+}
+using Rocket::Controls::ElementFormControlInput;
+LUACONTROLSTYPEDEFINE(ElementFormControlInput,true)
+}
+}
+}

+ 68 - 0
Source/Controls/Lua/ElementFormControlInput.h

@@ -0,0 +1,68 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAELEMENTFORMCONTROLINPUT_H
+#define ROCKETCONTROLSLUAELEMENTFORMCONTROLINPUT_H
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Controls/ElementFormControlInput.h>
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//getters
+int ElementFormControlInputGetAttrchecked(lua_State* L);
+int ElementFormControlInputGetAttrmaxlength(lua_State* L);
+int ElementFormControlInputGetAttrsize(lua_State* L);
+int ElementFormControlInputGetAttrmax(lua_State* L);
+int ElementFormControlInputGetAttrmin(lua_State* L);
+int ElementFormControlInputGetAttrstep(lua_State* L);
+
+//setters
+int ElementFormControlInputSetAttrchecked(lua_State* L);
+int ElementFormControlInputSetAttrmaxlength(lua_State* L);
+int ElementFormControlInputSetAttrsize(lua_State* L);
+int ElementFormControlInputSetAttrmax(lua_State* L);
+int ElementFormControlInputSetAttrmin(lua_State* L);
+int ElementFormControlInputSetAttrstep(lua_State* L);
+
+extern Rocket::Core::Lua::RegType<ElementFormControlInput> ElementFormControlInputMethods[];
+extern luaL_Reg ElementFormControlInputGetters[];
+extern luaL_Reg ElementFormControlInputSetters[];
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+//inherits from ElementFormControl which inherits from Element
+template<> void ExtraInit<Rocket::Controls::ElementFormControlInput>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::ElementFormControlInput)
+}}}
+#endif

+ 134 - 0
Source/Controls/Lua/ElementFormControlSelect.cpp

@@ -0,0 +1,134 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementFormControlSelect.h"
+#include "SelectOptionsProxy.h"
+#include <Rocket/Controls/ElementFormControlSelect.h>
+#include <Rocket/Controls/ElementFormControl.h>
+#include <Rocket/Core/Element.h>
+#include "ElementFormControl.h"
+#include <Rocket/Core/Lua/Utilities.h>
+
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//methods
+int ElementFormControlSelectAdd(lua_State* L, ElementFormControlSelect* obj)
+{
+    const char* rml = luaL_checkstring(L,1);
+    const char* value = luaL_checkstring(L,2);
+    int before = -1; //default
+    if(lua_gettop(L) >= 3)
+        before = luaL_checkint(L,3);
+
+    int index = obj->Add(rml,value,before);
+    lua_pushinteger(L,index);
+    return 1;
+}
+
+int ElementFormControlSelectRemove(lua_State* L, ElementFormControlSelect* obj)
+{
+    int index = luaL_checkint(L,1);
+    obj->Remove(index);
+    return 0;
+}
+
+//getters
+int ElementFormControlSelectGetAttroptions(lua_State* L)
+{
+    ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
+    LUACHECKOBJ(obj);
+    SelectOptionsProxy* proxy = new SelectOptionsProxy();
+    proxy->owner = obj;
+    LuaType<SelectOptionsProxy>::push(L,proxy,true);
+    return 1;
+}
+
+int ElementFormControlSelectGetAttrselection(lua_State* L)
+{
+    ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
+    LUACHECKOBJ(obj);
+    int selection = obj->GetSelection();
+    lua_pushinteger(L,selection);
+    return 1;
+}
+
+
+//setter
+int ElementFormControlSelectSetAttrselection(lua_State* L)
+{
+    ElementFormControlSelect* obj = LuaType<ElementFormControlSelect>::check(L,1);
+    LUACHECKOBJ(obj);
+    int selection = luaL_checkint(L,2);
+    obj->SetSelection(selection);
+    return 0;
+}
+
+
+Rocket::Core::Lua::RegType<ElementFormControlSelect> ElementFormControlSelectMethods[] =
+{
+    LUAMETHOD(ElementFormControlSelect,Add)
+    LUAMETHOD(ElementFormControlSelect,Remove)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormControlSelectGetters[] =
+{
+    LUAGETTER(ElementFormControlSelect,options)
+    LUAGETTER(ElementFormControlSelect,selection)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormControlSelectSetters[] =
+{
+    LUASETTER(ElementFormControlSelect,selection)
+    { NULL, NULL },
+};
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+//inherits from ElementFormControl which inherits from Element
+template<> void ExtraInit<Rocket::Controls::ElementFormControlSelect>(lua_State* L, int metatable_index)
+{
+    //init whatever elementformcontrol did extra, like inheritance
+    ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
+    //then inherit from elementformcontrol
+    LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
+    AddTypeToElementAsTable<Rocket::Controls::ElementFormControlSelect>(L);
+}
+using Rocket::Controls::ElementFormControlSelect;
+LUACONTROLSTYPEDEFINE(ElementFormControlSelect,true)
+}
+}
+}

+ 63 - 0
Source/Controls/Lua/ElementFormControlSelect.h

@@ -0,0 +1,63 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAELEMENTFORMCONTROLSELECT_H
+#define ROCKETCONTROLSLUAELEMENTFORMCONTROLSELECT_H
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Controls/ElementFormControlSelect.h>
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//methods
+int ElementFormControlSelectAdd(lua_State* L, ElementFormControlSelect* obj);
+int ElementFormControlSelectRemove(lua_State* L, ElementFormControlSelect* obj);
+
+//getters
+int ElementFormControlSelectGetAttroptions(lua_State* L);
+int ElementFormControlSelectGetAttrselection(lua_State* L);
+
+//setter
+int ElementFormControlSelectSetAttrselection(lua_State* L);
+
+extern Rocket::Core::Lua::RegType<ElementFormControlSelect> ElementFormControlSelectMethods[];
+extern luaL_Reg ElementFormControlSelectGetters[];
+extern luaL_Reg ElementFormControlSelectSetters[];
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+//inherits from ElementFormControl which inherits from Element
+template<> void ExtraInit<Rocket::Controls::ElementFormControlSelect>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::ElementFormControlSelect)
+}}}
+#endif

+ 150 - 0
Source/Controls/Lua/ElementFormControlTextArea.cpp

@@ -0,0 +1,150 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementFormControlTextArea.h"
+#include <Rocket/Controls/ElementFormControl.h>
+#include "ElementFormControl.h"
+#include <Rocket/Core/Lua/Utilities.h>
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//getters
+int ElementFormControlTextAreaGetAttrcols(lua_State* L)
+{
+    ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetNumColumns());
+    return 1;
+}
+
+int ElementFormControlTextAreaGetAttrmaxlength(lua_State* L)
+{
+    ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetMaxLength());
+    return 1;
+}
+
+int ElementFormControlTextAreaGetAttrrows(lua_State* L)
+{
+    ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->GetNumRows());
+    return 1;
+}
+
+int ElementFormControlTextAreaGetAttrwordwrap(lua_State* L)
+{
+    ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushboolean(L,obj->GetWordWrap());
+    return 1;
+}
+
+
+//setters
+int ElementFormControlTextAreaSetAttrcols(lua_State* L)
+{
+    ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L,1);
+    LUACHECKOBJ(obj);
+    int cols = luaL_checkint(L,2);
+    obj->SetNumColumns(cols);
+    return 0;
+}
+
+int ElementFormControlTextAreaSetAttrmaxlength(lua_State* L)
+{
+    ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L,1);
+    LUACHECKOBJ(obj);
+    int ml = luaL_checkint(L,2);
+    obj->SetMaxLength(ml);
+    return 0;
+}
+
+int ElementFormControlTextAreaSetAttrrows(lua_State* L)
+{
+    ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L,1);
+    LUACHECKOBJ(obj);
+    int rows = luaL_checkint(L,2);
+    obj->SetNumRows(rows);
+    return 0;
+}
+
+int ElementFormControlTextAreaSetAttrwordwrap(lua_State* L)
+{
+    ElementFormControlTextArea* obj = LuaType<ElementFormControlTextArea>::check(L,1);
+    LUACHECKOBJ(obj);
+    bool ww = CHECK_BOOL(L,2);
+    obj->SetWordWrap(ww);
+    return 0;
+}
+
+
+Rocket::Core::Lua::RegType<ElementFormControlTextArea> ElementFormControlTextAreaMethods[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormControlTextAreaGetters[] =
+{
+    LUAGETTER(ElementFormControlTextArea,cols)
+    LUAGETTER(ElementFormControlTextArea,maxlength)
+    LUAGETTER(ElementFormControlTextArea,rows)
+    LUAGETTER(ElementFormControlTextArea,wordwrap)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementFormControlTextAreaSetters[] =
+{
+    LUASETTER(ElementFormControlTextArea,cols)
+    LUASETTER(ElementFormControlTextArea,maxlength)
+    LUASETTER(ElementFormControlTextArea,rows)
+    LUASETTER(ElementFormControlTextArea,wordwrap)
+    { NULL, NULL },
+};
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Rocket::Controls::ElementFormControlTextArea>(lua_State* L, int metatable_index)
+{
+    ExtraInit<Rocket::Controls::ElementFormControl>(L,metatable_index);
+    LuaType<Rocket::Controls::ElementFormControl>::_regfunctions(L,metatable_index,metatable_index-1);
+    AddTypeToElementAsTable<Rocket::Controls::ElementFormControlTextArea>(L);
+}
+
+using Rocket::Controls::ElementFormControlTextArea;
+LUACONTROLSTYPEDEFINE(ElementFormControlTextArea,true)
+}
+}
+}

+ 64 - 0
Source/Controls/Lua/ElementFormControlTextArea.h

@@ -0,0 +1,64 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAELEMENTFORMCONTROLTEXTAREA_H
+#define ROCKETCONTROLSLUAELEMENTFORMCONTROLTEXTAREA_H
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Controls/ElementFormControlTextArea.h>
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//getters
+int ElementFormControlTextAreaGetAttrcols(lua_State* L);
+int ElementFormControlTextAreaGetAttrmaxlength(lua_State* L);
+int ElementFormControlTextAreaGetAttrrows(lua_State* L);
+int ElementFormControlTextAreaGetAttrwordwrap(lua_State* L);
+
+//setters
+int ElementFormControlTextAreaSetAttrcols(lua_State* L);
+int ElementFormControlTextAreaSetAttrmaxlength(lua_State* L);
+int ElementFormControlTextAreaSetAttrrows(lua_State* L);
+int ElementFormControlTextAreaSetAttrwordwrap(lua_State* L);
+
+extern Rocket::Core::Lua::RegType<ElementFormControlTextArea> ElementFormControlTextAreaMethods[];
+extern luaL_Reg ElementFormControlTextAreaGetters[];
+extern luaL_Reg ElementFormControlTextAreaSetters[];
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+//inherits from ElementFormControl which inherits from Element
+template<> void ExtraInit<Rocket::Controls::ElementFormControlTextArea>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::ElementFormControlTextArea)
+}}}
+#endif

+ 131 - 0
Source/Controls/Lua/ElementTabSet.cpp

@@ -0,0 +1,131 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "ElementTabSet.h"
+#include <Rocket/Core/Element.h>
+#include <Rocket/Core/Lua/Utilities.h>
+
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//methods
+int ElementTabSetSetPanel(lua_State* L, ElementTabSet* obj)
+{
+    LUACHECKOBJ(obj);
+    int index = luaL_checkint(L,1);
+    const char* rml = luaL_checkstring(L,2);
+
+    obj->SetPanel(index,rml);
+    return 0;
+}
+
+int ElementTabSetSetTab(lua_State* L, ElementTabSet* obj)
+{
+    LUACHECKOBJ(obj);
+    int index = luaL_checkint(L,1);
+    const char* rml = luaL_checkstring(L,2);
+
+    obj->SetTab(index,rml);
+    return 0;
+}
+
+
+//getters
+int ElementTabSetGetAttractive_tab(lua_State* L)
+{
+    ElementTabSet* obj = LuaType<ElementTabSet>::check(L,1);
+    LUACHECKOBJ(obj);
+    int tab = obj->GetActiveTab();
+    lua_pushinteger(L,tab);
+    return 1;
+}
+
+int ElementTabSetGetAttrnum_tabs(lua_State* L)
+{
+    ElementTabSet* obj = LuaType<ElementTabSet>::check(L,1);
+    LUACHECKOBJ(obj);
+    int num = obj->GetNumTabs();
+    lua_pushinteger(L,num);
+    return 1;
+}
+
+
+//setter
+int ElementTabSetSetAttractive_tab(lua_State* L)
+{
+    ElementTabSet* obj = LuaType<ElementTabSet>::check(L,1);
+    LUACHECKOBJ(obj);
+    int tab = luaL_checkint(L,2);
+    obj->SetActiveTab(tab);
+    return 0;
+}
+
+
+Rocket::Core::Lua::RegType<ElementTabSet> ElementTabSetMethods[] =
+{
+    LUAMETHOD(ElementTabSet,SetPanel)
+    LUAMETHOD(ElementTabSet,SetTab)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementTabSetGetters[] =
+{
+    LUAGETTER(ElementTabSet,active_tab)
+    LUAGETTER(ElementTabSet,num_tabs)
+    { NULL, NULL },
+};
+
+luaL_Reg ElementTabSetSetters[] =
+{
+    LUASETTER(ElementTabSet,active_tab)
+    { NULL, NULL },
+};
+
+
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+//this will be used to "inherit" from Element
+template<> void ExtraInit<Rocket::Controls::ElementTabSet>(lua_State* L, int metatable_index)
+{
+    ExtraInit<Element>(L,metatable_index);
+    LuaType<Element>::_regfunctions(L,metatable_index,metatable_index-1);
+    AddTypeToElementAsTable<Rocket::Controls::ElementTabSet>(L);
+}
+
+using Rocket::Controls::ElementTabSet;
+LUACONTROLSTYPEDEFINE(ElementTabSet,true)
+}
+}
+}

+ 64 - 0
Source/Controls/Lua/ElementTabSet.h

@@ -0,0 +1,64 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUAELEMENTTABSET_H
+#define ROCKETCONTROLSLUAELEMENTTABSET_H
+
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Controls/ElementTabSet.h>
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+//methods
+int ElementTabSetSetPanel(lua_State* L, ElementTabSet* obj);
+int ElementTabSetSetTab(lua_State* L, ElementTabSet* obj);
+
+//getters
+int ElementTabSetGetAttractive_tab(lua_State* L);
+int ElementTabSetGetAttrnum_tabs(lua_State* L);
+
+//setter
+int ElementTabSetSetAttractive_tab(lua_State* L);
+
+extern Rocket::Core::Lua::RegType<ElementTabSet> ElementTabSetMethods[];
+extern luaL_Reg ElementTabSetGetters[];
+extern luaL_Reg ElementTabSetSetters[];
+
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+//this will be used to "inherit" from Element
+template<> void ExtraInit<Rocket::Controls::ElementTabSet>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::ElementTabSet)
+}}}
+#endif

+ 100 - 0
Source/Controls/Lua/LuaDataFormatter.cpp

@@ -0,0 +1,100 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "LuaDataFormatter.h"
+#include <Rocket/Core/Lua/Interpreter.h>
+#include <Rocket/Core/Log.h>
+
+using Rocket::Core::Lua::Interpreter;
+using Rocket::Core::Log;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+LuaDataFormatter::LuaDataFormatter(const Rocket::Core::String& name) : Rocket::Controls::DataFormatter(name), ref_FormatData(LUA_NOREF)
+{
+    
+}
+
+LuaDataFormatter::~LuaDataFormatter()
+{
+    //empty
+}
+
+void LuaDataFormatter::FormatData(Rocket::Core::String& formatted_data, const Rocket::Core::StringList& raw_data)
+{
+    if(ref_FormatData == LUA_NOREF || ref_FormatData == LUA_REFNIL)
+    {
+        Log::Message(Log::LT_ERROR, "In LuaDataFormatter: There is no value assigned to the \"FormatData\" variable.");
+        return;
+    }
+    lua_State* L = Interpreter::GetLuaState();
+    int top = lua_gettop(L);
+    PushDataFormatterFunctionTable(L); // push the table where the function resides
+    lua_rawgeti(L,-1,ref_FormatData); //push the function
+    if(lua_type(L,-1) != LUA_TFUNCTION)
+    {
+        Log::Message(Log::LT_ERROR, "In LuaDataFormatter: The value for the FormatData variable must be a function. You passed in a %s.", lua_typename(L,lua_type(L,-1)));
+        lua_settop(L,top);
+        return;
+    }
+    lua_newtable(L); //to hold raw_data
+    int tbl = lua_gettop(L);
+    for(unsigned int i = 0; i < raw_data.size(); i++)
+    {
+        lua_pushstring(L,raw_data[i].CString());
+        lua_rawseti(L,tbl,i);
+    }
+    Interpreter::ExecuteCall(1,1); //1 parameter (the table), 1 result (a string)
+
+    //top of the stack should be the return value
+    if(lua_type(L,-1) != LUA_TSTRING)
+    {
+        Log::Message(Log::LT_ERROR, "In LuaDataFormatter: the return value of FormatData must be a string. You returned a %s.", lua_typename(L,lua_type(L,-1)));
+        lua_settop(L,top);
+        return;
+    }
+    formatted_data = Rocket::Core::String(lua_tostring(L,-1));
+    lua_settop(L,top);
+}
+
+void LuaDataFormatter::PushDataFormatterFunctionTable(lua_State* L)
+{
+    lua_getglobal(L,"LUADATAFORMATTERFUNCTIONS");
+    if(lua_isnoneornil(L,-1))
+    {
+        lua_newtable(L);
+        lua_setglobal(L,"LUADATAFORMATTERFUNCTIONS");
+        lua_pop(L,1); //pop the unsucessful getglobal
+        lua_getglobal(L,"LUADATAFORMATTERFUNCTIONS");
+    }
+}
+
+}
+}
+}

+ 55 - 0
Source/Controls/Lua/LuaDataFormatter.h

@@ -0,0 +1,55 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUALUADATAFORMATTER_H
+#define ROCKETCONTROLSLUALUADATAFORMATTER_H
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Controls/DataFormatter.h>
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+class LuaDataFormatter : public Rocket::Controls::DataFormatter
+{
+public:
+    LuaDataFormatter(const Rocket::Core::String& name = "");
+    ~LuaDataFormatter();
+
+    virtual void FormatData(Rocket::Core::String& formatted_data, const Rocket::Core::StringList& raw_data);
+
+    //Helper function used to push on to the stack the table where the function ref should be stored
+    static void PushDataFormatterFunctionTable(lua_State* L);
+
+    int ref_FormatData; //the lua reference to the FormatData function
+};
+
+}
+}
+}
+#endif

+ 113 - 0
Source/Controls/Lua/LuaDataSource.cpp

@@ -0,0 +1,113 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "LuaDataSource.h"
+#include <Rocket/Core/Lua/Interpreter.h>
+#include <Rocket/Core/Log.h>
+#include <Rocket/Core/String.h>
+
+using Rocket::Core::Lua::Interpreter;
+using Rocket::Core::Log;
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+LuaDataSource::LuaDataSource(const Rocket::Core::String& name) : DataSource(name), getRowRef(LUA_NOREF), getNumRowsRef(LUA_NOREF)
+{
+}
+
+/// Fetches the contents of one row of a table within the data source.
+/// @param[out] row The list of values in the table.
+/// @param[in] table The name of the table to query.
+/// @param[in] row_index The index of the desired row.
+/// @param[in] columns The list of desired columns within the row.
+void LuaDataSource::GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int row_index, const Rocket::Core::StringList& columns)
+{
+    if(getRowRef == LUA_NOREF || getRowRef == LUA_REFNIL) return;
+
+    //setup the call
+    Interpreter::BeginCall(getRowRef);
+    lua_State* L = Interpreter::GetLuaState();
+    lua_pushstring(L,table.CString());
+    lua_pushinteger(L,row_index);
+    lua_newtable(L);
+    int index = 0;
+    for(Rocket::Core::StringList::const_iterator itr = columns.begin(); itr != columns.end(); ++itr)
+    {
+        lua_pushstring(L,itr->CString());
+        lua_rawseti(L,-2,index++);
+    }
+    Interpreter::ExecuteCall(3,1); //3 parameters, 1 return. After here, the top of the stack contains the return value
+
+    int res = lua_gettop(L);
+    if(lua_type(L,res) == LUA_TTABLE)
+    {
+        lua_pushnil(L);
+        while(lua_next(L,res) != 0)
+        {
+            //key at -2, value at -1
+            row.push_back(luaL_checkstring(L,-1));
+            lua_pop(L,1); //pops value, leaves key for next iteration
+        }
+        lua_pop(L,1); //pop key
+    }
+    else
+        Log::Message(Log::LT_WARNING, "Lua: DataSource.GetRow must return a table, the function it called returned a %s", lua_typename(L,res));
+
+    Interpreter::EndCall(1);
+}
+
+/// Fetches the number of rows within one of this data source's tables.
+/// @param[in] table The name of the table to query.
+/// @return The number of rows within the specified table. Returns -1 in case of an incorrect Lua function.
+int LuaDataSource::GetNumRows(const Rocket::Core::String& table)
+{
+    if(getNumRowsRef == LUA_NOREF || getNumRowsRef == LUA_REFNIL) return -1;
+
+    lua_State* L = Interpreter::GetLuaState();
+    Interpreter::BeginCall(getNumRowsRef);
+    lua_pushstring(L,table.CString());
+    Interpreter::ExecuteCall(1,1); //1 parameter, 1 return. After this, the top of the stack contains the return value
+
+    int res = lua_gettop(L);
+    if(lua_type(L,res) == LUA_TNUMBER)
+    {
+        return luaL_checkint(L,res);
+    }
+    else
+    {
+        Log::Message(Log::LT_WARNING, "Lua: DataSource.GetNumRows must return an integer, the function it called returned a %s", lua_typename(L,res));
+        return -1;
+    }
+
+}
+
+}
+}
+}

+ 71 - 0
Source/Controls/Lua/LuaDataSource.h

@@ -0,0 +1,71 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUALUADATASOURCE_H
+#define ROCKETCONTROLSLUALUADATASOURCE_H
+
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Controls/DataSource.h>
+#include <Rocket/Core/String.h>
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+class LuaDataSource : public Rocket::Controls::DataSource
+{
+public:
+    //default initilialize the lua func references to -1
+    LuaDataSource(const Rocket::Core::String& name = "");
+
+	/// Fetches the contents of one row of a table within the data source.
+	/// @param[out] row The list of values in the table.
+	/// @param[in] table The name of the table to query.
+	/// @param[in] row_index The index of the desired row.
+	/// @param[in] columns The list of desired columns within the row.
+	virtual void GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int row_index, const Rocket::Core::StringList& columns);
+	/// Fetches the number of rows within one of this data source's tables.
+	/// @param[in] table The name of the table to query.
+	/// @return The number of rows within the specified table. Returns -1 in case of an incorrect Lua function.
+	virtual int GetNumRows(const Rocket::Core::String& table);
+
+    //make the protected members of DataSource public
+    using DataSource::NotifyRowAdd;
+    using DataSource::NotifyRowRemove;
+    using DataSource::NotifyRowChange;
+
+    //lua reference to DataSource.GetRow
+    int getRowRef;
+    //lua reference to DataSource.GetNumRows
+    int getNumRowsRef;
+};
+
+}
+}
+}
+#endif

+ 136 - 0
Source/Controls/Lua/SelectOptionsProxy.cpp

@@ -0,0 +1,136 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "SelectOptionsProxy.h"
+#include <Rocket/Core/Element.h>
+
+
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+
+
+int SelectOptionsProxy__index(lua_State* L)
+{
+    /*the table obj and the missing key are currently on the stack(index 1 & 2) as defined by the Lua language*/
+    int keytype = lua_type(L,2);
+    if(keytype == LUA_TNUMBER) //only valid key types
+    {
+        SelectOptionsProxy* proxy = LuaType<SelectOptionsProxy>::check(L,1);
+        LUACHECKOBJ(proxy);
+        int index = luaL_checkint(L,2);
+        Rocket::Controls::SelectOption* opt = proxy->owner->GetOption(index);
+        LUACHECKOBJ(opt);
+        lua_newtable(L);
+        LuaType<Rocket::Core::Element>::push(L,opt->GetElement(),false);
+        lua_setfield(L,-2,"element");
+        lua_pushstring(L,opt->GetValue().CString());
+        lua_setfield(L,-2,"value");
+        return 1;
+    }
+    else
+        return LuaType<SelectOptionsProxy>::index(L);
+}
+
+//since there are no string keys, just use __ipairs
+int SelectOptionsProxy__pairs(lua_State* L)
+{
+    return SelectOptionsProxy__ipairs(L);
+}
+
+//[1] is the object, [2] is the previous key, [3] is the userdata
+int SelectOptionsProxy__ipairs(lua_State* L)
+{
+    SelectOptionsProxy* proxy = LuaType<SelectOptionsProxy>::check(L,1);
+    LUACHECKOBJ(proxy);
+    int* pindex = (int*)lua_touserdata(L,3);
+    if((*pindex) == -1)
+        *pindex = 0;
+    SelectOption* opt = NULL;
+    while((*pindex) < proxy->owner->GetNumOptions())
+    {
+        opt = proxy->owner->GetOption((*pindex)++);
+        if(opt != NULL) 
+            break;
+    }
+    //we got to the end without finding an option
+    if(opt == NULL)
+    {
+        lua_pushnil(L);
+        lua_pushnil(L);
+    }
+    else //we found an option
+    {
+        lua_pushinteger(L,(*pindex)-1); //key
+        lua_newtable(L); //value
+        //fill the value
+        LuaType<Rocket::Core::Element>::push(L,opt->GetElement());
+        lua_setfield(L,-2,"element");
+        lua_pushstring(L,opt->GetValue().CString());
+        lua_setfield(L,-2,"value");
+    }
+    return 2;
+}
+
+Rocket::Core::Lua::RegType<SelectOptionsProxy> SelectOptionsProxyMethods[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg SelectOptionsProxyGetters[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg SelectOptionsProxySetters[] =
+{
+    { NULL, NULL },
+};
+
+
+}
+}
+}
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Rocket::Controls::Lua::SelectOptionsProxy>(lua_State* L, int metatable_index)
+{
+    lua_pushcfunction(L,Rocket::Controls::Lua::SelectOptionsProxy__index);
+    lua_setfield(L,metatable_index,"__index");
+    lua_pushcfunction(L,Rocket::Controls::Lua::SelectOptionsProxy__pairs);
+    lua_setfield(L,metatable_index,"__pairs");
+    lua_pushcfunction(L,Rocket::Controls::Lua::SelectOptionsProxy__ipairs);
+    lua_setfield(L,metatable_index,"__ipairs");
+}
+
+using Rocket::Controls::Lua::SelectOptionsProxy;
+LUACONTROLSTYPEDEFINE(SelectOptionsProxy,false);
+}
+}
+}

+ 57 - 0
Source/Controls/Lua/SelectOptionsProxy.h

@@ -0,0 +1,57 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCONTROLSLUASELECTOPTIONSPROXY_H
+#define ROCKETCONTROLSLUASELECTOPTIONSPROXY_H
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Controls/ElementFormControlSelect.h>
+
+using Rocket::Core::Lua::LuaType;
+namespace Rocket {
+namespace Controls {
+namespace Lua {
+//where owner is the ElementFormControlSelect that we should look up information from
+struct SelectOptionsProxy { Rocket::Controls::ElementFormControlSelect* owner;  };
+
+int SelectOptionsProxy__index(lua_State* L);
+int SelectOptionsProxy__pairs(lua_State* L);
+int SelectOptionsProxy__ipairs(lua_State* L);
+
+extern Rocket::Core::Lua::RegType<SelectOptionsProxy> SelectOptionsProxyMethods[];
+extern luaL_Reg SelectOptionsProxyGetters[];
+extern luaL_Reg SelectOptionsProxySetters[];
+
+}
+}
+}
+namespace Rocket { namespace Core { namespace Lua {
+template<> void ExtraInit<Rocket::Controls::Lua::SelectOptionsProxy>(lua_State* L, int metatable_index);
+LUACONTROLSTYPEDECLARE(Rocket::Controls::Lua::SelectOptionsProxy)
+}}}
+#endif

+ 35 - 0
Source/Controls/Lua/precompiled.h

@@ -0,0 +1,35 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCORELUAPRECOMPILED_H
+#define ROCKETCORELUAPRECOMPILED_H
+
+#include <Rocket/Core/Core.h>
+#include <Rocket/Core/Debug.h>
+#include <Rocket/Controls/Controls.h>
+#include <Rocket/Core/Lua/LuaType.h>
+#endif

+ 238 - 0
Source/Core/Lua/Colourb.cpp

@@ -0,0 +1,238 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "Colourb.h"
+
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+template<> void ExtraInit<Colourb>(lua_State* L, int metatable_index) 
+{
+    lua_pushcfunction(L,Colourbnew);
+    lua_setfield(L,metatable_index-1,"new");
+
+    lua_pushcfunction(L,Colourb__eq);
+    lua_setfield(L,metatable_index,"__eq");
+
+    lua_pushcfunction(L,Colourb__add);
+    lua_setfield(L,metatable_index,"__add");
+
+    lua_pushcfunction(L,Colourb__mul);
+    lua_setfield(L,metatable_index,"__mul");
+
+    return;
+}
+int Colourbnew(lua_State* L)
+{
+    byte red = (byte)luaL_checkint(L,1);
+    byte green = (byte)luaL_checkint(L,2);
+    byte blue = (byte)luaL_checkint(L,3);
+    byte alpha = (byte)luaL_checkint(L,4);
+
+    Colourb* col = new Colourb(red,green,blue,alpha);
+
+    LuaType<Colourb>::push(L,col,true);
+    return 1;
+}
+
+int Colourb__eq(lua_State* L)
+{
+    Colourb* lhs = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(lhs);
+    Colourb* rhs = LuaType<Colourb>::check(L,2);
+    LUACHECKOBJ(rhs);
+
+    lua_pushboolean(L, (*lhs) == (*rhs) ? 1 : 0);
+    return 1;
+}
+
+int Colourb__add(lua_State* L)
+{
+    Colourb* lhs = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(lhs);
+    Colourb* rhs = LuaType<Colourb>::check(L,2);
+    LUACHECKOBJ(rhs);
+
+    Colourb* res = new Colourb((*lhs) + (*rhs));
+
+    LuaType<Colourb>::push(L,res,true);
+    return 1;
+}
+
+int Colourb__mul(lua_State* L)
+{
+    Colourb* lhs = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(lhs);
+    float rhs = (float)luaL_checknumber(L,2);
+
+    Colourb* res = new Colourb((*lhs) * rhs);
+    
+    LuaType<Colourb>::push(L,res,true);
+    return 1;
+}
+
+
+
+//getters
+int ColourbGetAttrred(lua_State* L)
+{
+    Colourb* obj = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->red);
+    return 1;
+}
+
+int ColourbGetAttrgreen(lua_State* L)
+{
+    Colourb* obj = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->green);
+    return 1;
+}
+
+int ColourbGetAttrblue(lua_State* L)
+{
+    Colourb* obj = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->blue);
+    return 1;
+}
+
+int ColourbGetAttralpha(lua_State* L)
+{
+    Colourb* obj = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->alpha);
+    return 1;
+}
+
+int ColourbGetAttrrgba(lua_State* L)
+{
+    Colourb* obj = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushinteger(L,obj->red);
+    lua_pushinteger(L,obj->green);
+    lua_pushinteger(L,obj->blue);
+    lua_pushinteger(L,obj->alpha);
+    return 4;
+}
+
+
+//setters
+int ColourbSetAttrred(lua_State* L)
+{
+    Colourb* obj = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(obj);
+    byte red = (byte)luaL_checkinteger(L,2);
+    obj->red = red;
+    return 0;
+}
+
+int ColourbSetAttrgreen(lua_State* L)
+{
+    Colourb* obj = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(obj);
+    byte green = (byte)luaL_checkinteger(L,2);
+    obj->green = green;
+    return 0;
+}
+
+int ColourbSetAttrblue(lua_State* L)
+{
+    Colourb* obj = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(obj);
+    byte blue = (byte)luaL_checkinteger(L,2);
+    obj->blue = blue;
+    return 0;
+}
+
+int ColourbSetAttralpha(lua_State* L)
+{
+    Colourb* obj = LuaType<Colourb>::check(L,1);
+    LUACHECKOBJ(obj);
+    byte alpha = (byte)luaL_checkinteger(L,2);
+    obj->alpha = alpha;
+    return 0;
+}
+
+int ColourbSetAttrrgba(lua_State* L)
+{
+    Colourb* obj = NULL;
+    int top = lua_gettop(L);
+    //each of the items are optional.
+    if(top > 0)
+    {
+        obj = LuaType<Colourb>::check(L,1);
+        LUACHECKOBJ(obj);
+        if(top > 1)
+        {
+            if(top > 2)
+            {
+                if(top > 3)
+                    obj->alpha = luaL_checkint(L,4);
+                obj->blue = luaL_checkint(L,3);
+            }
+            obj->green = luaL_checkint(L,2);
+        }
+        obj->red = luaL_checkint(L,1);
+    }
+    return 0;
+}
+
+
+RegType<Colourb> ColourbMethods[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg ColourbGetters[] =
+{
+    LUAGETTER(Colourb,red)
+    LUAGETTER(Colourb,green)
+    LUAGETTER(Colourb,blue)
+    LUAGETTER(Colourb,alpha)
+    LUAGETTER(Colourb,rgba)
+    { NULL, NULL },
+};
+
+luaL_Reg ColourbSetters[] =
+{
+    LUASETTER(Colourb,red)
+    LUASETTER(Colourb,green)
+    LUASETTER(Colourb,blue)
+    LUASETTER(Colourb,alpha)
+    LUASETTER(Colourb,rgba)
+    { NULL, NULL },
+};
+
+LUACORETYPEDEFINE(Colourb,false)
+}
+}
+}

+ 68 - 0
Source/Core/Lua/Colourb.h

@@ -0,0 +1,68 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCORELUACOLOURB_H
+#define ROCKETCORELUACOLOURB_H
+
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Types.h>
+
+using Rocket::Core::Colourb;
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Colourb>(lua_State* L, int metatable_index);
+int Colourbnew(lua_State* L);
+int Colourb__eq(lua_State* L);
+int Colourb__add(lua_State* L);
+int Colourb__mul(lua_State* L);
+
+
+//getters
+int ColourbGetAttrred(lua_State* L);
+int ColourbGetAttrgreen(lua_State* L);
+int ColourbGetAttrblue(lua_State* L);
+int ColourbGetAttralpha(lua_State* L);
+int ColourbGetAttrrgba(lua_State* L);
+
+//setters
+int ColourbSetAttrred(lua_State* L);
+int ColourbSetAttrgreen(lua_State* L);
+int ColourbSetAttrblue(lua_State* L);
+int ColourbSetAttralpha(lua_State* L);
+int ColourbSetAttrrgba(lua_State* L);
+
+extern RegType<Colourb> ColourbMethods[];
+extern luaL_Reg ColourbGetters[];
+extern luaL_Reg ColourbSetters[];
+
+LUACORETYPEDECLARE(Colourb)
+}
+}
+}
+#endif

+ 210 - 0
Source/Core/Lua/Colourf.cpp

@@ -0,0 +1,210 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#include "precompiled.h"
+#include "Colourf.h"
+
+
+namespace Rocket {
+namespace Core {
+namespace Lua {
+
+template<> void ExtraInit<Colourf>(lua_State* L, int metatable_index)
+{
+    lua_pushcfunction(L,Colourfnew);
+    lua_setfield(L,metatable_index-1,"new");
+
+    lua_pushcfunction(L,Colourf__eq);
+    lua_setfield(L,metatable_index,"__eq");
+
+    return;
+}
+
+//metamethods
+int Colourfnew(lua_State* L)
+{
+    float red = (float)luaL_checknumber(L,1);
+    float green = (float)luaL_checknumber(L,2);
+    float blue =  (float)luaL_checknumber(L,3);
+    float alpha = (float)luaL_checknumber(L,4);
+
+    Colourf* col = new Colourf(red,green,blue,alpha);
+
+    LuaType<Colourf>::push(L,col,true);
+    return 1;
+}
+
+int Colourf__eq(lua_State* L)
+{
+    Colourf* lhs = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(lhs);
+    Colourf* rhs = LuaType<Colourf>::check(L,2);
+    LUACHECKOBJ(rhs);
+
+    lua_pushboolean(L, (*lhs) == (*rhs) ? 1 : 0);
+    return 1;
+}
+
+
+//getters
+int ColourfGetAttrred(lua_State* L)
+{
+    Colourf* obj = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushnumber(L,obj->red);
+    return 1;
+}
+
+int ColourfGetAttrgreen(lua_State* L)
+{
+    Colourf* obj = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushnumber(L,obj->green);
+    return 1;
+}
+
+int ColourfGetAttrblue(lua_State* L)
+{
+    Colourf* obj = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushnumber(L,obj->blue);
+    return 1;
+}
+
+int ColourfGetAttralpha(lua_State* L)
+{
+    Colourf* obj = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushnumber(L,obj->alpha);
+    return 1;
+}
+
+int ColourfGetAttrrgba(lua_State* L)
+{
+    Colourf* obj = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(obj);
+    lua_pushnumber(L,obj->red);
+    lua_pushnumber(L,obj->green);
+    lua_pushnumber(L,obj->blue);
+    lua_pushnumber(L,obj->alpha);
+    return 4;
+}
+
+
+//setters
+int ColourfSetAttrred(lua_State* L)
+{
+    Colourf* obj = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(obj);
+    float red = (float)luaL_checknumber(L,2);
+    obj->red = red;
+    return 0;
+}
+
+int ColourfSetAttrgreen(lua_State* L)
+{
+    Colourf* obj = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(obj);
+    float green = (float)luaL_checknumber(L,2);
+    obj->green = green;
+    return 0;
+}
+
+int ColourfSetAttrblue(lua_State* L)
+{
+    Colourf* obj = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(obj);
+    float blue = (float)luaL_checknumber(L,2);
+    obj->blue = blue;
+    return 0;
+}
+
+int ColourfSetAttralpha(lua_State* L)
+{
+    Colourf* obj = LuaType<Colourf>::check(L,1);
+    LUACHECKOBJ(obj);
+    float alpha = (float)luaL_checknumber(L,2);
+    obj->alpha = alpha;
+    return 0;
+}
+
+int ColourfSetAttrrgba(lua_State* L)
+{
+    Colourf* obj = NULL;
+    int top = lua_gettop(L);
+    //each of the items are optional.
+    if(top > 0)
+    {
+        obj = LuaType<Colourf>::check(L,1);
+        LUACHECKOBJ(obj);
+        if(top > 1)
+        {
+            if(top > 2)
+            {
+                if(top > 3)
+                    obj->alpha = (float)luaL_checknumber(L,4);
+                obj->blue = (float)luaL_checknumber(L,3);
+            }
+            obj->green = (float)luaL_checknumber(L,2);
+        }
+        obj->red = (float)luaL_checknumber(L,1);
+    }
+    return 0;
+}
+
+
+RegType<Colourf> ColourfMethods[] =
+{
+    { NULL, NULL },
+};
+
+luaL_Reg ColourfGetters[] =
+{
+    LUAGETTER(Colourf,red)
+    LUAGETTER(Colourf,green)
+    LUAGETTER(Colourf,blue)
+    LUAGETTER(Colourf,alpha)
+    LUAGETTER(Colourf,rgba)
+    { NULL, NULL },
+};
+
+luaL_Reg ColourfSetters[] =
+{
+    LUASETTER(Colourf,red)
+    LUASETTER(Colourf,green)
+    LUASETTER(Colourf,blue)
+    LUASETTER(Colourf,alpha)
+    LUASETTER(Colourf,rgba)
+    { NULL, NULL },
+};
+
+LUACORETYPEDEFINE(Colourf,false)
+
+
+}
+}
+}

+ 67 - 0
Source/Core/Lua/Colourf.h

@@ -0,0 +1,67 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+ 
+#ifndef ROCKETCORELUACOLOURF_H
+#define ROCKETCORELUACOLOURF_H
+
+#include <Rocket/Core/Lua/lua.hpp>
+#include <Rocket/Core/Lua/LuaType.h>
+#include <Rocket/Core/Types.h>
+
+using Rocket::Core::Colourf;
+namespace Rocket {
+namespace Core {
+namespace Lua {
+template<> void ExtraInit<Colourf>(lua_State* L, int metatable_index);
+//metamethods
+int Colourfnew(lua_State* L);
+int Colourf__eq(lua_State* L);
+
+//getters
+int ColourfGetAttrred(lua_State* L);
+int ColourfGetAttrgreen(lua_State* L);
+int ColourfGetAttrblue(lua_State* L);
+int ColourfGetAttralpha(lua_State* L);
+int ColourfGetAttrrgba(lua_State* L);
+
+//setters
+int ColourfSetAttrred(lua_State* L);
+int ColourfSetAttrgreen(lua_State* L);
+int ColourfSetAttrblue(lua_State* L);
+int ColourfSetAttralpha(lua_State* L);
+int ColourfSetAttrrgba(lua_State* L);
+
+extern RegType<Colourf> ColourfMethods[];
+extern luaL_Reg ColourfGetters[];
+extern luaL_Reg ColourfSetters[];
+
+LUACORETYPEDECLARE(Colourf)
+}
+}
+}
+#endif
+

Some files were not shown because too many files changed in this diff