### Setup Overloaded Functions Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/overload.md Example setup including struct definitions and free functions to be overloaded. ```cpp #define SOL_ALL_SAFETIES_ON 1 #include #include struct pup { int barks = 0; void bark() { ++barks; // bark! } bool is_cute() const { return true; } }; void ultra_bark(pup& p, int barks) { for (; barks-- > 0;) p.bark(); } void picky_bark(pup& p, std::string s) { if (s == "bark") p.bark(); } ``` -------------------------------- ### Install Library Targets and Files Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/CMakeLists.txt Handles the installation of targets, headers, and configuration files when installation is enabled. ```cmake if(SOL2_ENABLE_INSTALL) install(TARGETS sol2 EXPORT sol2) install(EXPORT sol2 NAMESPACE sol2:: FILE sol2-targets.cmake DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/sol2") install(DIRECTORY include/sol DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config-version.cmake" DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/sol2") endif() ``` -------------------------------- ### Customization Example Subdirectory Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/CMakeLists.txt Includes the subdirectory for in-depth customization examples. This allows for the integration and testing of advanced Sol2 customization features. ```cmake # # In-depth customization example add_subdirectory(customization) ``` -------------------------------- ### Enable Testing and Examples Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/CMakeLists.txt Configures CTest and adds subdirectories for examples and tests based on project flags. ```cmake # # Enable test harness for regular, example or single tests if (SOL2_DO_TESTS OR (SOL2_TESTS_EXAMPLES AND SOL2_DO_EXAMPLES)) # enable ctest message(STATUS "sol2 testing enabled...") enable_testing() endif() # # # Examples # # Enable examples to be built against the library if (SOL2_DO_EXAMPLES) # NOTE: will also add to tests if TESTS is defined message(STATUS "sol2 adding examples...") add_subdirectory(examples) endif() # # # Tests # # Add tests here if (SOL2_DO_TESTS) # add subdir to get going message(STATUS "sol2 adding tests...") ``` -------------------------------- ### Install Documentation Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/CMakeLists.txt Installs the generated Sphinx documentation to the CMAKE_INSTALL_DOCDIR destination. This makes the documentation accessible after the installation step. ```cmake # For the install target install(DIRECTORY ${SOL2_SPHINX_BUILD_DIR} DESTINATION ${CMAKE_INSTALL_DOCDIR} ) ``` -------------------------------- ### Sol2 Example Execution Logic Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/customization/CMakeLists.txt Conditionally creates Sol2 customization examples based on CMake variables. Use SOL2_EXAMPLES to build the default customization example and SOL2_EXAMPLES_SINGLE for a single-header variant. ```cmake if (SOL2_EXAMPLES) MAKE_CUSTOMIZATION_EXAMPLE("" sol2::sol2) endif() if (SOL2_EXAMPLES_SINGLE) MAKE_CUSTOMIZATION_EXAMPLE(".single" sol2::sol2::single) endif() ``` -------------------------------- ### Compile Example Project with Premake4 Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/3rdparty/nanosvg-master/README.md Build the NanoSVG example project using premake4. Navigate to the root folder and run the appropriate command for your OS (e.g., 'premake4 gmake' for Linux). ```bash premake4 gmake cd build/ make ./example ``` -------------------------------- ### Dynamic Loading Example Subdirectory Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/CMakeLists.txt Includes the subdirectory for dynamic loading examples if the SOL2_DYNAMIC_LOADING_EXAMPLES or SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE flags are enabled. This allows for separate compilation and testing of DLL-related features. ```cmake if (SOL2_DYNAMIC_LOADING_EXAMPLES OR SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE) # # require_from_dll example # just add the subdirectory add_subdirectory(require_dll_example) endif() ``` -------------------------------- ### Configure Build Modes and Installation Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/3rdparty/libaudiodecoder/README.md Use these commands to toggle between debug and release configurations or to perform a system-wide installation on Mac OS X. ```bash scons debug=1 ``` ```bash scons debug=0 ``` ```bash scons debug=0 install ``` -------------------------------- ### Sol2 Example Properties Configuration Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/CMakeLists.txt Configures properties for a Sol2 example target, including linking libraries like Threads and Lua, and setting compile definitions and options. This function is used to ensure examples are built with the correct settings. ```cmake function(sol2_add_example_properties target-name) ttarget_link_libraries(${target-name} PUBLIC Threads::Threads Lua::Lua ${CMAKE_DL_LIBS}) ttarget_compile_definitions(${target-name} PUBLIC SOL_PRINT_ERRORS=1) ttarget_compile_options(${target-name} PRIVATE ${--template-debugging-mode} ${--big-obj} ${--disable-permissive} ${--pedantic} ${--warn-all} ${--warn-pedantic} ${--warn-extra} ${--warn-errors} ${--utf8-literal-encoding} ${--utf8-source-encoding} ${--allow-unknown-warning} ${--allow-unknown-warning-option} ${--allow-noexcept-type} ${--allow-microsoft-cast} ${--allow-unreachable-code} ${--allow-padding-from-alignment} ) ttarget_compile_definitions(${target-name} PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) if (SOL2_CI) target_compile_definitions(${target-name} PRIVATE SOL2_CI) endif() if (SOL2_TESTS_EXAMPLES) add_test(NAME ${target-name} COMMAND ${target-name}) endif() if(SOL2_ENABLE_INSTALL) install(TARGETS ${target-name} RUNTIME DESTINATION bin) endif() endfunction() ``` -------------------------------- ### Interop Examples Subdirectories Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/CMakeLists.txt Includes subdirectories for various interop examples (kaguya, tolua, LuaBridge, luwra) if SOL2_INTEROP_EXAMPLES or SOL2_INTEROP_EXAMPLES_SINGLE flags are enabled. This allows for modular inclusion of different Lua binding libraries. ```cmake if (SOL2_INTEROP_EXAMPLES OR SOL2_INTEROP_EXAMPLES_SINGLE) # # interop examples add_subdirectory(interop/kaguya) add_subdirectory(interop/tolua) add_subdirectory(interop/LuaBridge) add_subdirectory(interop/luwra) endif() ``` -------------------------------- ### Conditional Example Compilation Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/CMakeLists.txt Compiles all Sol2 examples if SOL2_EXAMPLES is enabled, using the 'MAKE_EXAMPLE' function. This iterates through the found source files and creates executables for each. ```cmake if (SOL2_EXAMPLES) foreach(example_source_file ${sol2.examples.sources}) MAKE_EXAMPLE(${example_source_file} "sol2" sol2::sol2) endforeach() endif() ``` -------------------------------- ### Initialize a basic sol2 state Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/tutorial/getting-started.md A minimal example demonstrating how to include sol, create a state, and execute a simple Lua script. ```cpp #define SOL_ALL_SAFETIES_ON 1 #include // or #include "sol.hpp", whichever suits your needs int main(int argc, char* argv[]) { sol::state lua; lua.open_libraries(sol::lib::base); lua.script("print('bark bark bark!')"); return 0; } ``` -------------------------------- ### Coroutine Execution Example Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/lua/doc/manual.html Demonstrates the interaction between coroutine.create, coroutine.resume, and coroutine.yield. ```lua function foo (a) print("foo", a) return coroutine.yield(2*a) end co = coroutine.create(function (a,b) print("co-body", a, b) local r = foo(a+1) print("co-body", r) local r, s = coroutine.yield(a+b, a-b) print("co-body", r, s) return b, "end" end) print("main", coroutine.resume(co, 1, 10)) print("main", coroutine.resume(co, "r")) print("main", coroutine.resume(co, "x", "y")) print("main", coroutine.resume(co, "x", "y")) ``` -------------------------------- ### Sol2 Example Compilation Function Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/CMakeLists.txt Defines a CMake function 'MAKE_EXAMPLE' to create an executable for each Sol2 example source file. It handles naming, linking against the Sol2 library, and applying example-specific properties. ```cmake function (MAKE_EXAMPLE example_source_file example_prefix target_sol) get_filename_component(example_name ${example_source_file} NAME_WE) file(RELATIVE_PATH example_source_file_relative ${CMAKE_SOURCE_DIR} ${example_source_file}) get_filename_component(example_output_relative_dir ${example_source_file_relative} DIRECTORY) file(TO_CMAKE_PATH "${example_output_relative_dir}" example_output_relative_dir_name) STRING(REGEX REPLACE "/" "." example_output_relative_dir_name "${example_output_relative_dir_name}") if (example_output_relative_dir_name STREQUAL "") set(example_output_name ${example_name}) set(example_name "${example_prefix}.${example_name}") else() set(example_output_name ${example_output_relative_dir_name}.${example_name}) set(example_name "${example_prefix}.${example_output_relative_dir_name}.${example_name}") endif() add_executable(${example_name} ${example_source_file}) sol2_add_example_properties(${example_name}) target_link_libraries(${example_name} PRIVATE ${target_sol}) endfunction(MAKE_EXAMPLE) ``` -------------------------------- ### Conditional Single-File Example Compilation Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/CMakeLists.txt Compiles Sol2 examples as single-file executables if SOL2_EXAMPLES_SINGLE is enabled. This uses the 'MAKE_EXAMPLE' function with a 'sol2.single' prefix for the target names. ```cmake if (SOL2_EXAMPLES_SINGLE) foreach(example_source_file ${sol2.examples.sources}) MAKE_EXAMPLE(${example_source_file} "sol2.single" sol2::sol2::single) endforeach() endif() ``` -------------------------------- ### Compile a sol2 project Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/tutorial/getting-started.md Example command line for compiling a C++ file using g++ with the necessary include and library paths. ```pycon >>> g++ -std=c++17 test.cpp -I"path/to/sol/include" -I"path/to/lua/include" -L"path/to/lua/lib" -llua ``` -------------------------------- ### Lua Parameter and Vararg Handling Examples Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/lua/doc/manual.html Demonstrates how arguments are mapped to parameters and how vararg functions collect extra arguments using the '...' syntax. ```lua function f(a, b) end function g(a, b, ...) end function r() return 1,2,3 end CALL PARAMETERS f(3) a=3, b=nil f(3, 4) a=3, b=4 f(3, 4, 5) a=3, b=4 f(r(), 10) a=1, b=10 f(r()) a=1, b=2 g(3) a=3, b=nil, ... --> (nothing) g(3, 4) a=3, b=4, ... --> (nothing) g(3, 4, 5, 8) a=3, b=4, ... --> 5 8 g(5, r()) a=5, b=1, ... --> 2 3 ``` -------------------------------- ### Safe Script Execution Example Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/state.md Demonstrates using safe_script with default and custom error handlers to manage script execution failures. ```cpp #define SOL_ALL_SAFETIES_ON 1 #include #include int main() { std::cout << "=== safe_script usage ===" << std::endl; sol::state lua; // uses sol::script_default_on_error, which either panics or // throws, depending on your configuration and compiler // settings try { auto result1 = lua.safe_script("bad.code"); } catch (const sol::error& e) { std::cout << "an expected error has occurred: " << e.what() << std::endl; } // a custom handler that you write yourself // is only called when an error happens with loading or // running the script auto result2 = lua.safe_script("123 bad.code", [](lua_State*, sol::protected_function_result pfr) { // pfr will contain things that went wrong, for // either loading or executing the script the user // can do whatever they like here, including // throw. Otherwise... sol::error err = pfr; std::cout << "An error (an expected one) occurred: " << err.what() << std::endl; // ... they need to return the // protected_function_result return pfr; }); std::cout << std::endl; return 0; } ``` -------------------------------- ### Inheritance Registration Example Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/usertype.md Shows how to register base classes for a usertype to enable proper derived-to-base conversions. This is crucial when dealing with inheritance hierarchies in Sol2. ```cpp #define SOL_ALL_SAFETIES_ON 1 #include struct A { int a = 10; virtual int call() { return 0; } virtual ~A() { } }; struct B : A { int b = 11; virtual int call() override { return 20; } }; int main(int, char*[]) { sol::state lua; lua.new_usertype("A", "call", &A::call); lua.new_usertype("B", "call", &B::call, sol::base_classes, sol::bases()); return 0; } ``` -------------------------------- ### Configure Pkg-Config Support Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/CMakeLists.txt Generates and installs a pkg-config file for non-Windows platforms. ```cmake if(SOL2_ENABLE_INSTALL) # pkg-config support, except on Windows if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows) set(PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" CACHE PATH "Path where sol2.pc is installed") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sol2.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}") endif() endif() ``` -------------------------------- ### Demonstrate Expression Result Adjustment Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/lua/doc/manual.html Examples showing how function call results are adjusted based on their position in an expression list. ```Lua f() -- adjusted to 0 results g(f(), x) -- f() is adjusted to 1 result g(x, f()) -- g gets x plus all results from f() a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil) a,b = ... -- a gets the first vararg argument, b gets -- the second (both a and b can get nil if there -- is no corresponding vararg argument) a,b,c = x, f() -- f() is adjusted to 2 results a,b,c = f() -- f() is adjusted to 3 results return f() -- returns all results from f() return ... -- returns all received vararg arguments return x,y,f() -- returns x, y, and all results from f() {f()} -- creates a list with all results from f() {...} -- creates a list with all vararg arguments {f(), nil} -- f() is adjusted to 1 result ``` -------------------------------- ### Usertype Inheritance Setup Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/usertype.md Explains how to configure base classes for Sol2 usertypes to enable proper derived-to-base conversions. ```APIDOC ## Inheritance Sol2 can adjust pointers from derived classes to base classes at runtime. This requires explicit specification of base classes using `sol::base_classes` and `sol::bases()`. ### When to Specify Base Classes If your class hierarchy involves complicated virtual inheritance or multiple inheritance, you *must* specify the base classes. For simpler cases without these complexities, you might be able to omit them for a potential performance boost, but it's safer to always specify them if you plan to retrieve base classes via the Sol abstraction. ### Registration Example ```cpp #define SOL_ALL_SAFETIES_ON 1 #include struct A { int a = 10; virtual int call() { return 0; } virtual ~A() { } }; struct B : A { int b = 11; virtual int call() override { return 20; } }; int main(int, char*[]) { sol::state lua; lua.new_usertype("A", "call", &A::call); lua.new_usertype("B", "call", &B::call, sol::base_classes, sol::bases()); return 0; } ``` #### NOTE Always specify your base classes if you intend to retrieve a base class using the Sol abstraction directly, rather than performing manual casting. ``` -------------------------------- ### Initialize ldCore and Configure Audio Source: https://context7.com/wickedlasers/liblaserdockcore/llms.txt This snippet shows the basic setup for initializing the ldCore singleton, configuring the default audio input device, and setting up a visualizer task. Ensure Qt resources are initialized before QApplication. ```cpp #include #include #include int main(int argc, char *argv[]) { // Initialize Qt resources before QApplication ldCore::initResources(); QGuiApplication app(argc, argv); // Create and initialize ldCore singleton ldCore* core = ldCore::create(&app); core->initialize(); // Configure audio input device ldSoundDeviceManager* soundMgr = core->soundDeviceManager(); soundMgr->setDeviceInfo(soundMgr->getDefaultDevice(ldSoundDeviceInfo::Type::QAudioInput)); // Disable startup logo (optional) core->task()->setIsShowLogo(false); // Set a visualizer to start rendering MyVisualizer* vis = new MyVisualizer(); core->task()->setVisualizer(vis); return app.exec(); } ``` -------------------------------- ### Lua Closures and Upvalues Example Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/lua/doc/manual.html Demonstrates how local variables can become upvalues when used by inner functions (closures). Each closure created within a loop gets its own 'y' but shares the same 'x'. ```lua a = {} local x = 20 for i=1,10 do local y = 0 a[i] = function () y=y+1; return x+y end end ``` -------------------------------- ### Call Lua Function with C Abstraction Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/stack.md Use this function to bind to raw C functions and leverage sol2's abstractions for argument setup when interacting with Lua. The 'start' parameter indicates where to pull arguments from the stack. ```cpp template inline int call_lua(lua_State* L, int start, Fx&& fx, FxArgs&&... fxargs); ``` -------------------------------- ### Initialize TCP and UDP Servers in main() Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/3rdparty/abletonlink/link/modules/asio-standalone/asio/src/examples/cpp03/tutorial/daytime_dox.txt Create server objects for accepting TCP connections and UDP requests. This sets up the asio::io_context to manage both types of asynchronous operations. ```cpp asio::io_context io_context; // Create a server object to accept a TCP client connection. tcp_server server(io_context); // Create a server object to accept a UDP client request. udp_server server2(io_context); // We have created two lots of work for the asio::io_context object to do. io_context.run(); return 0; ``` -------------------------------- ### Globbing Source Files for Examples Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/CMakeLists.txt Uses file globbing to find all C++ source files for Sol2 examples, including those in 'source/', 'source/tutorials/', and 'source/docs/'. This is used to dynamically compile all example files. ```cmake # # single-source compilable examples file(GLOB sol2.examples.sources source/*.cpp source/tutorials/*.cpp source/tutorials/quick_n_dirty/*.cpp source/docs/*.cpp) ``` -------------------------------- ### Timer.3 Source Listing Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/3rdparty/abletonlink/link/modules/asio-standalone/asio/src/examples/cpp03/tutorial/timer_dox.txt Full source code for the Timer.3 tutorial, demonstrating the use of Boost.Bind with a free function as a completion handler. ```cpp #include #include #include void print(const asio::error_code& /*e*/, int count) { if (count < 5) { std::cout << "Count: " << count << std::endl; return; } std::cout << "Final count: " << count << std::endl; } int main() { asio::io_context io_context; int count = 0; asio::steady_timer timer(io_context); timer.expires_at(timer.expiry() + std::chrono::seconds(1)); timer.async_wait(boost::bind(print, asio::placeholders::error, ++count)); io_context.run(); return 0; } ``` -------------------------------- ### Implement sol::environment for script sandboxing Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/environment.md Demonstrates creating isolated environments with and without global fallbacks. ```cpp #define SOL_ALL_SAFETIES_ON 1 #include int main(int, char*[]) { sol::state lua; lua.open_libraries(); sol::environment my_env(lua, sol::create); // set value, and we need to explicitly allow for // access to "print", since a new environment hides // everything that's not defined inside of it // NOTE: hiding also hides library functions (!!) // BE WARNED my_env["var"] = 50; my_env["print"] = lua["print"]; sol::environment my_other_env( lua, sol::create, lua.globals()); // do not need to explicitly allow access to "print", // since we used the "Set a fallback" version // of the sol::environment constructor my_other_env["var"] = 443; // output: 50 lua.script("print(var)", my_env); // output: 443 lua.script("print(var)", my_other_env); return 0; } ``` -------------------------------- ### Table Creation with Arguments Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/table.md Creates a table and populates it with provided arguments, automatically generating capacity hints. ```cpp template table create_with(Args&&... args); template static table create_with(lua_State* L, Args&&... args); ``` -------------------------------- ### Windows Visual Studio Debug Environment Setup Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/example/CMakeLists.txt Configures the startup project for Visual Studio 2015 and 2017 generators and copies a user project file for debugging. ```cmake if(CMAKE_GENERATOR STREQUAL "Visual Studio 14 2015" OR CMAKE_GENERATOR STREQUAL "Visual Studio 15 2017") set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) configure_file(project.vcxproj.user.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.vcxproj.user @ONLY) endif() ``` -------------------------------- ### Raw Get Values from Lua Table Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/table.md Retrieves values from a Lua table without invoking metamethods. Similar to 'get' and 'traverse_get' but operates directly on the table data. ```cpp template decltype(auto) raw_get(Keys&&... keys) const; template decltype(auto) traverse_raw_get(Keys&&... keys) const; template decltype(auto) raw_get_or(Key&& key, T&& otherwise) const; template decltype(auto) raw_get_or(Key&& key, D&& otherwise) const; ``` -------------------------------- ### Open multiple Lua libraries Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/tutorial/getting-started.md Demonstrates how to load multiple standard Lua libraries into the sol state. ```cpp #define SOL_ALL_SAFETIES_ON 1 #include int main(int argc, char* argv[]) { sol::state lua; lua.open_libraries(sol::lib::base, sol::lib::coroutine, sol::lib::string, sol::lib::io); lua.script("print('bark bark bark!')"); return 0; } ``` -------------------------------- ### Build LuaBridge Interop Example with Sol2 Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/interop/LuaBridge/CMakeLists.txt This CMake code conditionally calls the `make_luabridge_interop_example` function to build an interop example. It can be configured to build a standard version or a single-header version. ```cmake if (SOL2_INTEROP_EXAMPLES) make_luabridge_interop_example(sol2::sol2 "") endif() if (SOL2_INTEROP_EXAMPLES_SINGLE) make_luabridge_interop_example(sol2::sol2::single ".single") endif() ``` -------------------------------- ### Proxy Get or Create Value Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/proxy.md Gets the value associated with the keys if it exists. If it does not, it will set the value with a default or provided value and return the result. This function returns decltype(auto). ```cpp template decltype(auto) get_or_create(); template decltype(auto) get_or_create( Otherwise&& other ); ``` -------------------------------- ### Proxy Get Value or Default Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/proxy.md Gets the value associated with the keys and converts it to type T. If the value is not of the proper type, it returns a sol::nullopt. An 'otherwise' value can be provided. ```cpp template optional get_or( Otherwise&& otherise ) const; ``` -------------------------------- ### Proxy Get Value (Explicit) Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/proxy.md Explicitly gets the value associated with the keys the proxy was generated for and converts it to the type T. This function returns decltype(auto), allowing for perfect forwarding. ```cpp template decltype(auto) get( ) const; ``` -------------------------------- ### Enable Qt Quick Support in CMake Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/ldCore/CMakeLists.txt Configures sources, compile definitions, and links the Qt Quick module. Includes conditional configuration for OpenGL simulator support. ```cmake if(LD_CORE_ENABLE_QT_QUICK) target_sources(${PROJECT_NAME} PRIVATE ${SRCDIR}/Simulator/ldQSGSimulatorItem.cpp ${INCDIR}/Simulator/ldQSGSimulatorItem.h ) target_compile_definitions(${PROJECT_NAME} PRIVATE LD_CORE_ENABLE_QT_QUICK) find_package(Qt${QT_VERSION_MAJOR} ${QT_MIN_VERSION} COMPONENTS Quick REQUIRED) target_link_libraries(${PROJECT_NAME} PUBLIC Qt::Quick) if(LD_CORE_USE_OPENGL) target_sources(${PROJECT_NAME} PRIVATE ${SRCDIR}/Simulator/ldSimulatorItem.cpp ${INCDIR}/Simulator/ldSimulatorItem.h ${SRCDIR}/Simulator/ldSimulatorRenderer.cpp ${INCDIR}/Simulator/ldSimulatorRenderer.h ) target_compile_definitions(${PROJECT_NAME} PUBLIC LD_CORE_ENABLE_OPENGL_SIMULATOR) endif() endif() ``` -------------------------------- ### Define LuaBridge Interop Example Function Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/interop/LuaBridge/CMakeLists.txt This function defines a CMake target for a LuaBridge interop example. It links against Lua, LuaBridge, and Sol2 libraries. Specific compiler options are set for MSVC and other compilers. ```cmake function (make_luabridge_interop_example target_library example_suffix) set(example_name luabridge_interop_example) set(example_name "${example_name}${example_suffix}") add_executable(${example_name} source/LuaBridge.cpp) target_link_libraries(${example_name} PRIVATE Lua::Lua ${LUABRIDGE_LIBRARIES} ${target_library} ${CMAKE_DL_LIBS}) if (MSVC) target_compile_options(${example_name} PRIVATE /std:c++latest /EHsc "$<$:/MDd>" "$<$:/MD>" "$<$:/MD>" "$<$:/MD>") target_compile_definitions(${example_name} PRIVATE /W1 UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) else() target_compile_options(${example_name} PRIVATE -std=c++1z -w -Wno-unknown-warning -Wno-unknown-warning-option) endif() if (SOL2_TESTS_INTEROP_EXAMPLES) add_test(NAME ${example_name} COMMAND ${example_name}) endif() endfunction() ``` -------------------------------- ### Configure SimpleCrypt Library Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/3rdparty/simplecrypt/CMakeLists.txt Sets up the simplecrypt library, including its sources, include directories, and compile definitions. It also handles conditional linking for OpenMP. ```cmake cmake_minimum_required(VERSION 3.10) set(SIMPLECRYPT_XOR_KEY "0" CACHE STRING "Simplecrypt ") add_library(simplecrypt) set_property(TARGET simplecrypt PROPERTY AUTOMOC OFF) set_property(TARGET simplecrypt PROPERTY AUTORCC OFF) set_property(TARGET simplecrypt PROPERTY AUTOUIC OFF) target_include_directories(simplecrypt PUBLIC .) target_sources(simplecrypt PRIVATE simplecrypt.cpp simplecrypt.h ) find_package(Qt${QT_VERSION_MAJOR} CONFIG REQUIRED Core) target_link_libraries(simplecrypt PRIVATE Qt::Core ) target_compile_definitions(simplecrypt PRIVATE SIMPLECRYPT_XOR_KEY=${SIMPLECRYPT_XOR_KEY}) if(LD_CORE_ENABLE_OPENMP) target_link_libraries(simplecrypt PUBLIC 3rdparty::openmp ) endif() if(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) add_library(${PROJECT_NAME}::simplecrypt ALIAS simplecrypt) endif() ``` -------------------------------- ### Get Values from Lua Table Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/table.md Retrieves values from a Lua table. 'get' can fetch multiple values into a std::tuple, while 'traverse_get' retrieves a single value through nested lookups. Use 'get_or' for default values. ```cpp template decltype(auto) get(Keys&&... keys) const; template decltype(auto) traverse_get(Keys&&... keys) const; template decltype(auto) get_or(Key&& key, T&& otherwise) const; template decltype(auto) get_or(Key&& key, D&& otherwise) const; ``` -------------------------------- ### Creating and Managing Threads Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/thread.md Demonstrates how to create and interact with `sol::thread` objects, including retrieving their state and status. ```APIDOC ## Thread Constructors ### `thread(stack_reference r)` Constructs a `thread` object from a `stack_reference`. ### `thread(lua_State* L, int index = -1)` Constructs a `thread` object from a `lua_State` at a specific stack index. ### `thread(lua_State* L, lua_State* actual_thread)` Constructs a `thread` object from a `lua_State` and an actual thread state. ## Thread Member Functions ### `state_view state() const` Retrieves the current state of the thread, returning a `state_view` that can be manipulated. ### `lua_State* thread_state() const` Retrieves the `lua_State*` that represents the thread. ### `thread_status status() const` Retrieves the status of the thread, indicating its current state. ### `bool is_main_thread() const` Checks if the current thread is the main Lua thread. ``` -------------------------------- ### Example of sol::protect with usertypes Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/protect.md This C++ example demonstrates using sol::protect with a usertype. It exposes a 'gen' method of 'protect_me' to Lua, ensuring that calls to it are protected. When an incorrect argument is passed in Lua, the pcall wrapper fails as expected. ```cpp #define SOL_ALL_SAFETIES_ON 1 #include int main(int, char*[]) { struct protect_me { int gen(int x) { return x; } }; sol::state lua; lua.open_libraries(sol::lib::base); lua.new_usertype( "protect_me", "gen", sol::protect(&protect_me::gen)); lua.script(R"__( pm = protect_me.new() value = pcall(pm.gen,"wrong argument") )__"); bool value = lua["value"]; SOL_ASSERT(!value); return 0; } ``` -------------------------------- ### Configure CMake for libqtqmltricks Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/3rdparty/lib-qt-qml-tricks/CMakeLists.txt Initializes the library target and sets up archive creation flags for compatibility with Xcode generators. ```cmake cmake_minimum_required(VERSION 3.11) add_library(libqtqmltricks) SET(CMAKE_C_ARCHIVE_CREATE " Scr ") SET(CMAKE_CXX_ARCHIVE_CREATE " Scr ") if(CMAKE_GENERATOR STREQUAL Xcode) SET(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") endif() ``` -------------------------------- ### file:seek Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/lua/doc/manual.html Sets and gets the file position. ```APIDOC ## file:seek ### Description Sets and gets the file position, measured from the beginning of the file. ### Parameters #### Query Parameters - **whence** (string) - Optional - Base position: 'set' (beginning), 'cur' (current), 'end' (end of file). Default is 'cur'. - **offset** (number) - Optional - Offset from base. Default is 0. ``` -------------------------------- ### Conditional Build for Dynamic Loading Examples Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/examples/require_dll_example/CMakeLists.txt This code checks if the Lua library is statically linked. If it is, the script returns to avoid linking issues. Otherwise, it conditionally calls the 'make_require_from_dll_example' function to build dynamic loading examples based on CMake variables. ```cmake list(GET LUA_LIBRARIES 0 lua_lib_target) get_target_property(lua_lib_type ${lua_lib_target} TYPE) if (lua_lib_type MATCHES "STATIC") # avoid multiply defined references due to linking in the same static library # twice over, and get "multiple definition" errors during linking return() endif() if (SOL2_DYNAMIC_LOADING_EXAMPLES) make_require_from_dll_example(sol2::sol2 "") endif() if (SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE) make_require_from_dll_example(sol2::sol2::single ".single") endif() ``` -------------------------------- ### get Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/stack.md Retrieves a value from the Lua stack at a specified index. ```APIDOC ## get ### Description Retrieves the value of the object at the specified index in the stack. The return type depends on the template parameter T. ### Parameters - **L** (lua_State*) - Required - The Lua state. - **index** (int) - Optional - The stack index (defaults to -1). - **tracking** (record&) - Optional - Tracking record for the operation. ``` -------------------------------- ### Create Lua Values and Tables Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/lua_value.md Demonstrates initializing various Lua values, including nested tables and custom C++ objects, using sol::lua_value and sol::array_value. ```cpp #define SOL_ALL_SAFETIES_ON 1 #include #include #include struct int_entry { int value; int_entry() : value(0) { } int_entry(int v) : value(v) { } std::string to_string() const { return "int_entry(" + std::to_string(value) + ")"; } bool operator==(const int_entry& e) const { return value == e.value; } }; int main(int, char*[]) { std::cout << "=== sol::lua_value/sol::array_value ===" << std::endl; sol::state lua; lua.open_libraries(sol::lib::base, sol::lib::io); sol::lua_value lv_int(lua, 56); sol::lua_value lv_int_table(lua, { 1, 2, 3, 4, 5 }); sol::lua_value lv_map(lua, { { "bark bark", "meow hiss!" }, { 3, 4 }, { ":D", 6 } }); sol::lua_value lv_mixed_table(lua, sol::array_value { 1, int_entry(2), 3, int_entry(4), 5 }); sol::lua_value lv_mixed_nested_table(lua, sol::array_value { 1, int_entry(2), 3, int_entry(4), sol::array_value { 5, 6, int_entry(7), "8" } }); const auto& code = R"( function real_print_recursive (e, level) local et = type(e) if et == 'table' then io.write("{ ") local iters = 0 for k, v in pairs(e) do if iters ~= 0 then io.write(", ") end real_print_recursive(k, level + 1) io.write(": ") real_print_recursive(v, level + 1) iters = iters + 1 end io.write(" }") elseif et == 'string' then io.write('"') io.write(e) io.write('"') else io.write(tostring(e)) end if level == 0 then io.write("\n") end end function print_recursive (e) real_print_recursive(e, 0) end )"; sol::optional maybe_error = lua.safe_script(code, sol::script_pass_on_error); if (maybe_error) { std::cerr << maybe_error->what() << std::endl; return 1; } sol::function print_recursive = lua["print_recursive"]; // show it printed out std::cout << "lv_int: " << std::endl; print_recursive(lv_int); std::cout << std::endl; std::cout << "lv_int_table: " << std::endl; print_recursive(lv_int_table); std::cout << std::endl; std::cout << "lv_map: " << std::endl; print_recursive(lv_map); std::cout << std::endl; std::cout << "lv_mixed_table: " << std::endl; print_recursive(lv_mixed_table); std::cout << std::endl; std::cout << "lv_mixed_nested_table: " << std::endl; print_recursive(lv_mixed_nested_table); std::cout << std::endl; std::cout << std::endl; return 0; } ``` -------------------------------- ### Runtime Extension Example Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/usertype.md Demonstrates adding functions to a usertype at runtime through both the Sol2 API and a Lua script. Functions added this way are available to all instances of the usertype. ```cpp #define SOL_ALL_SAFETIES_ON 1 #include #include struct object { int value = 0; }; int main(int, char*[]) { std::cout << "==== runtime_extension ===== ``` -------------------------------- ### Get lua_State pointer Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/reference.md Retrieves the lua_State associated with the reference. ```cpp lua_State* lua_state() const noexcept; ``` -------------------------------- ### Setup USB and Network Hardware Managers Source: https://context7.com/wickedlasers/liblaserdockcore/llms.txt This function demonstrates how to set up the `ldHardwareManager` to discover and manage both USB and network-connected Laserdock devices. It initializes device check timers and connects to device count change signals. ```cpp #include #include #include #include void setupHardware() { ldCore* core = ldCore::instance(); ldHardwareManager* hwMgr = core->hardwareManager(); // Add USB hardware manager ldUsbHardwareManager* usbMgr = new ldUsbHardwareManager(core->filterManager()); hwMgr->addHardwareManager(usbMgr); // Add Network hardware manager for WiFi Cube support ldNetworkHardwareManager* netMgr = new ldNetworkHardwareManager(core->filterManager()); hwMgr->addHardwareManager(netMgr); // Initialize device check timer hwMgr->initCheckTimer(); // Connect to device count changes QObject::connect(hwMgr, &ldHardwareManager::deviceCountChanged, [](uint count) { qDebug() << "Connected devices:" << count; }); // Activate all connected devices hwMgr->setConnectedDevicesActive(true); // Get current device count int deviceCount = hwMgr->getDeviceCount(); // Access individual devices std::vector devices = hwMgr->devices(); for (ldHardware* device : devices) { qDebug() << "Device ID:" << device->id(); } // Force a specific DAC rate (optional) hwMgr->setForcedDACRate(30000); // 30kHz } ``` -------------------------------- ### Get Environment Variable Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/lua/doc/manual.html Retrieves the value of a process environment variable. ```APIDOC ## os.getenv (varname) ### Description Returns the value of the process environment variable `varname`, or **nil** if the variable is not defined. ### Parameters * **varname** (string) - The name of the environment variable. ### Returns * (string or nil) - The value of the environment variable, or **nil** if not defined. ``` -------------------------------- ### Get Field Functions Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/stack.md Functions for retrieving fields from Lua tables. ```APIDOC ## `sol::stack::get_field` ### Description Retrieves a field from a Lua table. It pushes the key onto the stack and performs `lua_getfield`. Optimizations are applied for C-style string keys or global fields. The retrieved value is left on the stack. ### Method `template void get_field( lua_State* L, Key&& k [, int objectindex] );` ### Endpoint N/A (C++ function) ### Parameters - `L` (lua_State*) - The Lua state. - `global` (bool) - If true, treats the key as a global. - `k` (Key&&) - The key of the field to retrieve. - `objectindex` (int, optional) - The index of the object in the stack from which to retrieve the field. ### Request Example ```cpp // Get a field from the current table sol::stack::get_field(L, "my_key"); // The value is now on top of the stack // Get a global field sol::stack::get_field(L, "global_var"); // Get a field from a specific stack index sol::stack::get_field(L, "nested_key", -2); ``` ### Response None (void function). The retrieved value is left on the Lua stack. ``` -------------------------------- ### Configure Visual Studio for 64-bit Compiler Tools Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/errors.md Add this to your .vcxproj file to use the 64-bit compiler, which increases available heap space and resolves "compiler out of heap space" errors. This is typically placed under the \ statement. ```xml x64 ``` -------------------------------- ### Configure Basic Laser Filters Source: https://context7.com/wickedlasers/liblaserdockcore/llms.txt Demonstrates instantiation and configuration of various filter classes for color, transformation, and effect processing. Requires including ldBasicFilters.h. ```cpp #include void setupIndividualFilters() { // Color replacement filter ldColorFilter colorFilter; colorFilter.enabled = true; colorFilter.r = 1.0f; // Red component colorFilter.g = 0.0f; // Green component colorFilter.b = 0.5f; // Blue component // Flip/mirror filter ldFlipFilter flipFilter; flipFilter.flipX = true; // Mirror horizontally flipFilter.flipY = false; // Don't mirror vertically // Zoom filter with independent X/Y control ldZoomFilter zoomFilter; zoomFilter.set_xScale(1.5f); // 150% X scale zoomFilter.set_yScale(0.8f); // 80% Y scale // Position offset filter ldPosFilter posFilter; posFilter.set_x(0.2f); // Offset X posFilter.set_y(-0.1f); // Offset Y // Scale filter ldScaleFilter scaleFilter; scaleFilter.setEnabled(true); scaleFilter.setXScale(0.9f); scaleFilter.setYScale(0.9f); // Shift filter (with scale awareness) std::vector scales = {&scaleFilter}; ldShiftFilter shiftFilter(scales); shiftFilter.x = 0.1f; shiftFilter.y = 0.05f; // TTL output mode ldTtlFilter ttlFilter; ttlFilter.m_enabled = true; // Enable TTL color mode // Hue matrix filter (complex hue transformation) ldHueMatrixFilter hueMatrix; hueMatrix.m_enabled = true; hueMatrix.m_value = 0.7f; // 0 to 1 // Apply filter to a vertex ldVertex v; v.x = 0.5f; v.y = 0.5f; v.r = 1.0f; v.g = 0.0f; v.b = 0.0f; colorFilter.process(v); } ``` -------------------------------- ### Check for nil value Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/object.md Example usage of comparing an object against sol::lua_nil. ```cpp if (myobj == sol::lua_nil) { // doesn't have anything... } ``` -------------------------------- ### Table Creation with Capacity Source: https://github.com/wickedlasers/liblaserdockcore/blob/master/modules/ldLuaGame/3rdparty/sol2/documentation/source/api/table.md Creates a table with optional pre-set values and capacity hints for array and hashable entries. ```cpp table create(int narr = 0, int nrec = 0); template table create(int narr, int nrec, Key&& key, Value&& value, Args&&... args); static table create(lua_State* L, int narr = 0, int nrec = 0); template static table create(lua_State* L, int narr, int nrec, Key&& key, Value&& value, Args&&... args); ```