Lua is a simple, small, fast, easy to learn embeddable language. It can be very useful in projects such as Algine, since there are a lot of things that we can do much easier with language like Lua.
Firstly, we need Lua to get rid of awful, overcomplicated, inflexible, hard to maintain json configs that we are now using in Creators.
Secondly, we need Lua to simplify developer's lives - not all projects need to be written in C++, so in this case easy to learn language like Lua would be a great solution.
And finally, we need Lua to create Editor, since it will be much easier to create it using language like Lua.
Lua support is provided by the solgen library.
An approximate list of classes that need lua support to be implemented:
Creators:
- Creator
- ShaderCreator
- ShaderDefinitionGenerator
- ShaderProgramCreator
- TextureCreator
- Texture2DCreator
- TextureCubeCreator
- ImageCreator
- FramebufferCreator
- RenderbufferCreator
-
OutputListCreator(removed, some functionality was moved to OutputList) -
InputLayoutShapeLocationsCreator(removed, InputLayoutShapeLocations was extended in functionality) - ModelCreator
- ShapeCreator
Core:
- Engine
- Object
- Log
- IOProvider
- IOSystem
- IOStream
- StandardIOStream
- StandardIOSystem
- AssetsIOStream
- AssetsIOSystem
- Buffer
- ArrayBuffer
- IndexBuffer
- UniformBuffer
- Shader
- ShaderProgram
- Texture
- Texture2D
- TextureCube
- Framebuffer
- Renderbuffer
- InputLayout
- OutputList
- Resources
- Point
- Rect
- Color
- Font
- FontLibrary
- FontMetrics
- FontRenderer
Widgets:
- Paint
- Painter
- RoundRect
- Alignment
- Container
- Dimen
- ImageWidget
- Label
- Layout
- LinearLayout
- RelativeLayout
- SizePolicy
- Unit
- Units
- Widget
Std:
- InputLayoutShapeLocations
- Mesh
- Model
- Shape
- Rotatable
- Translatable
- Scalable
- Rotator
- EulerRotator
- FreeRotator
- Animation
- AnimationBlender
- Animator
- Bone
- BonesStorage
- Camera
- Material
- AMTLManager
- AMTLMaterialManager
Glm:
- vec3
- vec4
- mat3
- mat4
- quat
- basic functions
Tulz:
- Array
- UnsignedArray
- IntArray
- FloatArray
- DoubleArray
In reality this list will be much bigger
- Redefine Lua's
require
to load Algine types (base, widgets, core (base+widgets), std, glm, tulz), e.g.require('algine:core')
- Redefine Lua's
tostring
for tables - Redefine Lua's
print
to add ability to print tables
- Sol documentation: https://sol2.readthedocs.io/en/latest/
- Sol - C++ in Lua - basic class binding example: https://sol2.readthedocs.io/en/latest/tutorial/cxx-in-lua.html
- Sol - property: https://sol2.readthedocs.io/en/latest/api/property.html
- Sol - usertype: https://sol2.readthedocs.io/en/latest/api/usertype.html
- Sol - ownership: https://sol2.readthedocs.io/en/latest/tutorial/ownership.html
- Sol - environment: https://sol2.readthedocs.io/en/latest/api/environment.html
- Programming in Lua: https://www.lua.org/pil/contents.html
- Lua OOP: https://www.tutorialspoint.com/lua/lua_object_oriented.htm
- How to pass table as vector to a c++ function: ThePhD/sol2#1054
- Virtual inheritance: https://en.wikipedia.org/wiki/Virtual_inheritance
- To create binding to overloaded function use
static_cast<return_type (T::*)(args)>(&T::function_name)
- To create binding to overloaded static function use
static_cast<return_type (*)(args)>(&T::function_name)
- If you bind class member function to lambda, then the 1st argument will be self:
usertype["function"] = [](const sol::object &self, ...) { self.as<T>().function(...); };
Lua::new_enum
allows you to create an enum and then make it as a class memberLua::new_property
creates property and additionally makes getter and setter- If you inherit
Scriptable
, then you also need to definestatic void registerLuaUsertype(Lua *lua)