Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lua and Databroker support #190

Merged
merged 22 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ab2fc45
engine: Remove --distinct option from check command
cassava Mar 10, 2023
9a7a556
engine: Set stack options in own scope
cassava Mar 16, 2023
87d82bc
engine: Extract SimulationProgress into simulation_progress.hpp
cassava May 10, 2023
93b4d24
runtime: Add CallbackResult return value to all action operator()
cassava May 16, 2024
5ba0e6d
engine: Restructure code for better compilation times
cassava May 16, 2024
2bed94a
basic: Replace boost::optional with std::optional
cassava May 16, 2024
12b60b5
engine: Vendor linenoise library
cassava May 24, 2023
f06ce82
engine: Add Lua scripting support
cassava May 16, 2024
e014958
engine: Add LRDB debugging support
cassava May 16, 2024
a0b8569
all: Add DataBroker and Signals concepts
cassava May 16, 2024
2769fb2
engine: Replace boost::optional with std::optional
cassava Oct 26, 2023
2e847d3
runtime: Replace boost::filesystem with std::filesystem
cassava Nov 6, 2023
a155f8b
engine: Replace boost::filesystem with std::filesystem
cassava Nov 6, 2023
b4a84c7
engine: Add --output-path to cloe-engine
CzBalti Dec 14, 2023
26e43e2
tests: Add test for cloe-engine --write-output and --output-path
cassava Apr 30, 2024
79ec670
tooling: Add VS Code project configuration
CzBalti Jun 12, 2024
4e30255
tooling: Improve grep-uuids to better show duplicates
cassava Jun 13, 2024
13ad0fb
speedometer: Implement data broker
cassava Jun 13, 2024
a00f1d5
all: Improve DataBroker interface for common types
cassava Jun 26, 2024
9afe3a4
runtime: Fix duplicate definitions in set_action.hpp
cassava Jun 26, 2024
a4c0943
engine: Fix some findings from clang-tidy
cassava Jun 26, 2024
e206cb0
engine: Add probe subcommand
cassava Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
8 changes: 8 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"workspace.library": ["engine/lua"],
"runtime.version": "Lua 5.4",
"completion.displayContext": 1,
"diagnostics.globals": ["cloe"],
"hint.enable": true
}
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64",
//run `make configure` to create the file
"compileCommands": "${workspaceFolder}/compile_commands.json"
}
],
"version": 4
}
76 changes: 76 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"configurations": [
{
"name": "Debug cloe",
"type": "cppdbg",
"request": "launch",
"program": "${input:get_executable_path}",
"args": [
"run",
"--write-output",
"${workspaceFolder}/${input:get_test_case}",
//Example to run a specific test-case
//"${workspaceFolder}/tests/test_lua04_schedule_test.lua",
//Example to run a specific smoketest
//"-u",
//"smoketest",
//"${workspaceFolder}/tests/test_engine_replica_smoketest_temp.json",
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "Build Cloe",
"miDebuggerPath": "/usr/bin/gdb",
"envFile": "${input:get_shell_path}"
}
],
"inputs": [
{
"type": "command",
"id": "get_test_case",
"command": "shellCommand.execute",
"args":{
"command":"ls tests/*.lua",
"cwd": "${workspaceFolder}"
}
},
{
"type": "command",
"id": "get_shell_path",
"command": "shellCommand.execute",
//bash magic to set CLOE_SHELL variable and get the value of it
"args": {
"command": "bash -c \"source <(PYTHONPATH=\"${workspaceFolder}/cli\" python3 -m cloe_launch activate tests/conanfile_all.py) && printenv CLOE_SHELL\"",
"cwd": "${workspaceFolder}",
"useSingleResult": "true"
}
},
{
"type": "command",
"id": "get_executable_path",
"command": "shellCommand.execute",
//bash magic to set CLOE_ENGINE variable and get the value of it
"args": {
//"command": "bash -c \"source <(cloe-launch activate tests/conanfile_all.py) && printenv CLOE_ENGINE\"",
"command": "bash -c \"source <(PYTHONPATH=\"${workspaceFolder}/cli\" python3 -m cloe_launch activate tests/conanfile_all.py) && printenv CLOE_ENGINE\"",
"cwd": "${workspaceFolder}",
"useSingleResult": "true"
}
}
],
"version": "2.0.0"
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"tasks": [
{
"type": "shell",
"label": "Build Cloe",
"command": "make",
"args": [
"all",
"BUILD_TYPE=Debug"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "shell",
"label": "Build Cloe (without tests)",
"command": "make",
"args": [
"all",
"CONAN_OPTIONS=\"-c tools.build:skip_test=1\"",
"CONAN_RUN_TESTS=0",
"BUILD_TYPE=Debug"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
],
"version": "2.0.0"
}
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ todos:

.PHONY: grep-uuids
grep-uuids:
$(AG) "\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b"
@rg -H --no-heading '^.*([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}).*$$' -r '$$1' \
| sed -nr 's/^(.+):([a-f0-9-]+)$$/\1\t\2/p' \
| sort -k2 \
| uniq --all-repeated=separate -f1 \
| sed -r 's/^(.*) (.*)$$/\2\t\1/'

.PHONY: grep-conan-requires
grep-conan-requires:
@rg -t py '^.*requires\(f?["](.+/[0-9]+\.[^)]+)["].*\).*$$' -r '$$1' -I --no-heading --no-line-number | sort | uniq

Expand Down
38 changes: 37 additions & 1 deletion NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@ The following third-party libraries are included in the Cloe repository:
- Website: https://jothepro.github.io/doxygen-awesome-css
- Source: docs/_vendor/doxygen-awesome

- Typecheck
- License: MIT
- License-Source: https://github.com/gvvaughan/typecheck/raw/master/LICENSE.md
- Website: https://github.com/gvvaughan/typecheck
- Source: engine/lua/typecheck.lua

- Tableshape
- License: MIT
- License-Source: https://github.com/leafo/tableshape/blob/v2.6.0/README.md
- Website: https://github.com/leafo/tableshape
- Source: engine/lua/tableshape.lua

- Linenoise
- License: BSD2
- License-Source: https://raw.githubusercontent.com/antirez/linenoise/master/LICENSE
- Website: https://github.com/antirez/linenoise
- Source: engine/vendor/linenoise

- Inspect.lua
- License: MIT
- License-Source: https://raw.githubusercontent.com/kikito/inspect.lua/master/MIT-LICENSE.txt
- Website: https://github.com/kikito/inspect.lua
- Source: engine/lua/inspect.lua

- LRDB
- License: BSL-1.0
- License-Source: https://www.boost.org/LICENSE_1_0.txt
- Website: https://github.com/satoren/LRDB
- Source: engine/vendor/lrdb

- Lust
- License: MIT
- License-Source: https://raw.githubusercontent.com/bjornbytes/lust/master/LICENSE
- Website: https://github.com/bjornbytes/lust
- Source: engine/lua/lust.lua

The following third-party libraries are used by this project (these are usually
installed with the help of Conan):

Expand Down Expand Up @@ -93,7 +129,7 @@ installed with the help of Conan):
- Conan-Package: inja

- Boost
- License: Boost
- License: BSL-1.0
- License-Source: https://www.boost.org/LICENSE_1_0.txt
- Website: https://www.boost.org
- Conan-Package: boost
Expand Down
11 changes: 10 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Cloe(ConanFile):
"fPIC": [True, False],
"fable_allow_comments": [True, False],
"engine_server": [True, False],
"engine_lrdb": [True, False],
"with_esmini": [True, False],
"with_vtd": [True, False],
}
Expand All @@ -58,6 +59,7 @@ class Cloe(ConanFile):
"fPIC": True,
"fable_allow_comments": True,
"engine_server": True,
"engine_lrdb": True,
"with_esmini": True,
"with_vtd": False,
}
Expand All @@ -72,7 +74,9 @@ class Cloe(ConanFile):

"fable/examples/*",

"engine/lua/*",
"engine/webui/*",
"engine/vendor/*",

"CMakelists.txt"
]
Expand All @@ -93,6 +97,7 @@ def requirements(self):
self.requires("incbin/cci.20211107"),
self.requires("inja/3.4.0")
self.requires("nlohmann_json/3.11.3")
self.requires("sol2/3.3.1")
self.requires("spdlog/1.11.0")
if self.options.engine_server:
self.requires("oatpp/1.3.0", private=True)
Expand All @@ -105,7 +110,6 @@ def requirements(self):

def build_requirements(self):
self.test_requires("gtest/1.14.0")
self.test_requires("sol2/3.3.0")

def layout(self):
cmake.cmake_layout(self)
Expand All @@ -132,6 +136,7 @@ def generate(self):
tc.cache_variables["CLOE_VERSION"] = self.version
tc.cache_variables["CLOE_VERSION_U32"] = version_u32
tc.cache_variables["CLOE_ENGINE_WITH_SERVER"] = self.options.engine_server
tc.cache_variables["CLOE_ENGINE_WITH_LRDB"] = self.options.engine_lrdb
tc.cache_variables["CLOE_WITH_ESMINI"] = self.options.with_esmini
tc.cache_variables["CLOE_WITH_VTD"] = self.options.with_vtd
tc.generate()
Expand Down Expand Up @@ -195,14 +200,18 @@ def package_info(self):
self.cpp_info.builddirs.append(os.path.join(self.source_folder, "cmake"))
self.cpp_info.includedirs.append(os.path.join(self.build_folder, "include"))
bindir = os.path.join(self.build_folder, "bin")
luadir = os.path.join(self.source_folder, "engine/lua")
libdir = os.path.join(self.build_folder, "lib");
else:
self.cpp_info.builddirs.append(os.path.join("lib", "cmake", "cloe"))
bindir = os.path.join(self.package_folder, "bin")
luadir = os.path.join(self.package_folder, "lib/cloe/lua")
libdir = None

self.output.info(f"Appending PATH environment variable: {bindir}")
self.runenv_info.prepend_path("PATH", bindir)
self.output.info(f"Appending CLOE_LUA_PATH environment variable: {luadir}")
self.runenv_info.prepend_path("CLOE_LUA_PATH", luadir)
if libdir is not None:
self.output.info(f"Appending LD_LIBRARY_PATH environment variable: {libdir}")
self.runenv_info.append_path("LD_LIBRARY_PATH", libdir)
4 changes: 4 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ background knowledge for any of the following topics.
:doc:`reference/plugins`
provides an overview of all plugins that are part of the Cloe distribution.

:doc:`reference/lua-initialization`
provides an overview of how the engine processes a Lua file.

.. toctree::
:hidden:

Expand All @@ -62,3 +65,4 @@ background knowledge for any of the following topics.
reference/events
reference/actions
reference/plugins
reference/lua-initialization
38 changes: 38 additions & 0 deletions docs/reference/lua-initialization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Lua Initialization
------------------

When a Lua file or script is loaded, the Cloe engine provides a preloaded
`cloe` table with a large API. This API is defined in part through a Lua
runtime, and in part from the C++ engine itself.

The following operations occur when the engine runs a simulation defined
by a Lua file: `cloe-engine run simulation.lua`

1. Read options from the command line and environment:

- Lua package path (`--lua-path`, `CLOE_LUA_PATH`)
- Disable system packages (`--no-system-lua`)
- Enable LRDB Lua debugger (`--debug-lua`)
- Cloe plugins (`--plugin-path`, `CLOE_PLUGIN_PATH`)

2. Initialize Cloe Stack

- Load plugins found in plugin path

3. Initialize Lua

- Set lua package path
- Load built-in Lua base libraries (e.g. `os`, `string`)
- Expose Cloe API via `cloe` Lua table
- Load Cloe Lua runtime (located in the package `lib/cloe/lua` directory)

4. Start LRDB Lua debugger (Optional)

5. Source input files

- Files ending with `.lua` are merged as Lua
- Other files are read as JSON

6. Start simulation

- Schedule triggers pending from the Lua script
5 changes: 5 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ guides will give you a better feel for how Cloe works and how it is built up.
usage/viewing-cloe-registry
usage/running-cloe-webui
usage/creating-a-stackfile

usage/lua-introduction
usage/lua-cloe-shell
usage/lua-editor-integration

usage/configuring-plugins-in-stackfiles
usage/writing-modular-stackfiles
usage/user-cloe-configuration
Expand Down
Loading
Loading