Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
31ecc18
ignore: some CMake stuff
DataM0del Nov 12, 2024
b22067c
add: CMakeLists.txt
DataM0del Nov 12, 2024
7b43356
chore: put Windows.h includes behind _WIN32 flag
DataM0del Nov 12, 2024
3b9fdeb
feat(file.hpp): support non-Win32 OSes (Unix/Linux)
DataM0del Nov 12, 2024
adea4d1
fix(CMakeLists.txt): add `shared` to include directories
DataM0del Nov 12, 2024
f37e2b8
chore: add Luau as a submodule because yes
DataM0del Nov 12, 2024
d553b17
fix: submodule URL & add submodule file thingy
DataM0del Nov 12, 2024
374a393
TODO(CMakeLists.txt): Luau library linking thing not working
DataM0del Nov 12, 2024
6f186ae
fix(CMakeLists.txt): works now
DataM0del Nov 12, 2024
7d663ab
fix(CMakeLists.txt): finally compiles past the Luau part...
DataM0del Nov 12, 2024
64b3a83
fix(shared/file.hpp): eww Cursor what did you do
DataM0del Nov 12, 2024
ee9ca46
add: c_cpp_properties.json
DataM0del Nov 12, 2024
d1f0f21
chore: replace usages of `DWORD` with `unsigned long`
DataM0del Nov 12, 2024
85a8c67
chore(runluau-build-template): use `errno` on non-Windows builds.
DataM0del Nov 12, 2024
3050467
chore(main.cpp): define `ERROR_INVALID_PARAMETER` as EINVAL on non-Wi…
DataM0del Nov 12, 2024
3b38c60
chore(main.cpp): replace more `DWORD` references with `unsigned long`
DataM0del Nov 12, 2024
6984f43
chore(main.cpp): #define ERROR_INTERNAL_ERROR
DataM0del Nov 12, 2024
86c58c6
chore(main.cpp/ctrl_handler): add Unix support
DataM0del Nov 12, 2024
7de7a91
chore(CMakeLists.txt): change minimum required version to 3.20
DataM0del Nov 12, 2024
35e6f58
chore(main.cpp): define ERROR_NOT_FOUND, ERROR_OUTOFMEMORY
DataM0del Nov 12, 2024
c14dfb5
fix(main.cpp): #include "luau.h"
DataM0del Nov 12, 2024
0264905
fix(luau.h): handle non-MSVC compilers for `API`
DataM0del Nov 12, 2024
863f6a2
fix(CMakeLists.txt): change C++ standard to C++20
DataM0del Nov 12, 2024
896f98b
Merge branch 'plusgiant5:main' into main
DataM0del Nov 12, 2024
693faaf
fix: non-local lambda expression can't have a capture-default
DataM0del Nov 12, 2024
a8dd0fb
chore(Luau): update submodule
DataM0del Nov 12, 2024
0e3f225
refactor: move error `#define`s into `errors.h`
DataM0del Nov 13, 2024
91c7392
fix(execute.cpp): include `errors.h`
DataM0del Nov 13, 2024
887de65
fix(main.cpp): move include `errors.h` above other includes
DataM0del Nov 13, 2024
a0bebd8
add(errors.h): ERROR_FILE_NOT_FOUND
DataM0del Nov 13, 2024
977a99f
chore: stop with the jerry rigging
DataM0del Nov 13, 2024
fb5ab7d
Merge branch 'plusgiant5:main' into main
DataM0del Nov 23, 2024
099f190
Merge branch 'main' into main
DataM0del Dec 4, 2024
756f5ea
chore: update Luau submodule
DataM0del Dec 4, 2024
5d67a08
chore: remove build system (will rewrite later)
DataM0del Dec 4, 2024
548f552
fix: wrap virtual terminal processing mode setting in _WIN32 ifdef
DataM0del Dec 4, 2024
408c805
fix: including Lua headers (e.g. lualib.h) when we should've included…
DataM0del Dec 4, 2024
ce5db03
add(shared/errors.h): ERROR_MOD_NOT_FOUND > ENOENT
DataM0del Dec 4, 2024
827e733
feat: port load_plugin to Linux
DataM0del Dec 4, 2024
1347a6b
chore(luau.h): define `__fastcall` when not using MSVC
DataM0del Dec 4, 2024
509e52d
fix(shared/luau.h): remove useless #endif at the end of the file
DataM0del Dec 4, 2024
31f68e8
fix(shared/luau.h): that was actually needed stupid me
DataM0del Dec 4, 2024
25307b3
chore: move macros into macros.h
DataM0del Dec 4, 2024
43aeeb9
fix(plugins.cpp): include macros.h + use dlsym on Linux
DataM0del Dec 4, 2024
a8fee4c
add(shared/errors.h): ERROR_CIRCULAR_DEPENDENCY -> EINVAL
DataM0del Dec 4, 2024
64c65a9
fix(plugins.cpp): no more errors!
DataM0del Dec 4, 2024
00b0cb2
chore: merge upstream
DataM0del Mar 20, 2025
4e726a2
chore: update Luau
DataM0del Mar 20, 2025
975dd7c
fix: some errors
DataM0del Mar 20, 2025
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
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ FodyWeavers.xsd
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/c_cpp_properties.json
*.code-workspace

# Local History for Visual Studio Code
Expand All @@ -396,3 +397,18 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

# CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
.cmake
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Luau"]
path = Luau
url = https://github.com/luau-lang/luau.git
5 changes: 0 additions & 5 deletions .rc

This file was deleted.

19 changes: 19 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/shared/",
"${workspaceFolder}/Luau/CodeGen/include",
"${workspaceFolder}/Luau/Ast/include",
"${workspaceFolder}/Luau/Common/include",
"${workspaceFolder}/Luau/Compiler/include"
],
"defines": [],
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.20)
project(runluau LANGUAGES CXX C)

# Set C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)

if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIX")
elseif(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINDOWS")
endif()

include_directories(shared)


# Add Luau submodule as a subdirectory
add_subdirectory(Luau ${CMAKE_BINARY_DIR}/_deps/Luau)

# Include Luau directories (adjust as needed)
include_directories(Luau/Compiler/include)
include_directories(Luau/Ast/include)
include_directories(Luau/CodeGen/include)
include_directories(Luau/Common/include)

# Add your source files
add_executable(runluau main.cpp execute.cpp plugins.cpp)

# Link against Luau libraries
target_link_libraries(runluau Luau)
1 change: 1 addition & 0 deletions Luau
Submodule Luau added at e0b55a
6 changes: 6 additions & 0 deletions execute.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#include "execute.h"

#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif

#include <Luau/Compiler.h>

#include "colors.h"
#include "plugins.h"
#include "errors.h"
#include "base_funcs.h"
#include "Luau/VM/include/lualib.h"

using namespace runluau;

Expand Down
4 changes: 2 additions & 2 deletions luau-dynamic/luau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ API bool luau::resume_and_handle_status(lua_State* thread, lua_State* from, int
void luau::start_scheduler() {
HANDLE timer = CreateWaitableTimer(NULL, TRUE, NULL);
if (!timer) {
DWORD error = GetLastError();
unsigned long error = GetLastError();
printf("Failed to CreateWaitableTimer: %d\n", error);
exit(error);
}
Expand Down Expand Up @@ -252,7 +252,7 @@ void luau::start_scheduler() {

API void signal_yield_ready(yield_ready_event_t yield_ready_event) {
if (!SetEvent(yield_ready_event)) {
DWORD error = GetLastError();
unsigned long error = GetLastError();
printf("Failed to SetEvent: %d\n", error);
exit(error);
}
Expand Down
4 changes: 4 additions & 0 deletions luau-dynamic/pch.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif

#include <list>
#include <format>
Expand Down
39 changes: 33 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include <stdio.h>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#include <csignal>
#include <signal.h>
#endif

#include <cerrno>
#include <string>
Expand All @@ -8,11 +14,13 @@
#include <fstream>
#include <format>

#include "errors.h"
#include "file.h"
#include "execute.h"
#include "plugins.h"
#include "build.h"
#include "luaurc.h"
#include "luau.h"

void help_then_exit(std::string notice_message) {
printf(R"(%s Help is below:
Expand All @@ -22,9 +30,7 @@ runluau <mode> <...>
Modes:
- Run a script. `args` is optional. If specified, everything after it will be passed into the script. If not specified, `script` will be set to "init".
runluau run <path>? <options> --args <...>
- Build a script to an executable, with an optional list of plugins to embed into the output. If `plugins` isn't specified, it will use every plugin installed.
runluau build <path> <output> <options> --plugins <...>
Options for `run` and `build`:
Options:
- [default: 1] Optimization level 0-2:
-O/-o <n>
- [default: 1] Debug level 0-2:
Expand Down Expand Up @@ -89,25 +95,46 @@ runluau::settings_run_build read_args_run_build(std::vector<std::string>& args,
return settings;
}

BOOL WINAPI ctrl_handler(DWORD type) {
inline uintptr_t align(uintptr_t value, uintptr_t alignment) {
return (value + (alignment - 1)) & ~(alignment - 1);
}
#ifdef _WIN32
BOOL WINAPI ctrl_handler(unsigned long type) {
#else
int ctrl_handler(int type) {
#endif
switch (type) {
#ifdef _WIN32
case CTRL_C_EVENT:
#else
case SIGINT:
#endif
printf("Exiting\n");
#ifdef _WIN32
__fastfail(ERROR_PROCESS_ABORTED);
return TRUE;
#else
raise(SIGABRT);
#endif
return 1;
default:
return FALSE;
return 0;
}
}
int main(int argc, char* argv[]) {
#ifdef _WIN32
SetConsoleCtrlHandler(ctrl_handler, TRUE);
#else
signal(SIGINT, (void(*)(int))ctrl_handler);
#endif
#ifdef _WIN32
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
if (console) {
DWORD mode;
GetConsoleMode(console, &mode);
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(console, mode);
}
#endif
std::vector<std::string> args(argv + 1, argv + argc);
const auto minimum_arguments = [&args](size_t amount) -> void {
if (args.size() - 1 < amount) {
Expand Down
49 changes: 37 additions & 12 deletions plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,56 @@
#include <unordered_set>
#include <stack>
#include <vector>
#ifdef _WIN32
#include <Windows.h>

#else
#include <unistd.h>
#include <dlfcn.h>
#endif
#include "errors.h"
#include "macros.h"
#include "luau.h"

typedef void(__fastcall* register_library_t)(lua_State* state);
typedef const char**(__fastcall* get_dependencies_t)();


#ifdef _WIN32
HMODULE load_plugin(const fs::path& path) {
HMODULE plugin_module = GetModuleHandleW(path.wstring().c_str());
if (!plugin_module) {
plugin_module = LoadLibraryW(path.wstring().c_str());
if (!plugin_module) {
wprintf(L"Failed to load plugin %s\n", path.wstring().c_str());
exit(ERROR_MOD_NOT_FOUND);
}
HMODULE plugin_module = LoadLibraryW(path.wstring().c_str());
if (!plugin_module) [[unlikely]] {
wprintf(L"Failed to load plugin %s\n", path.wstring().c_str());
exit(ERROR_MOD_NOT_FOUND);
}
return plugin_module;
}

#else
void* load_plugin(const fs::path& path) {
void* plugin_module = dlopen(path.c_str(), RTLD_LAZY);
if (!plugin_module) [[unlikely]] {
fprintf(stderr, "Failed to load plugin %s\n", dlerror());
exit(ERROR_MOD_NOT_FOUND);
}
return plugin_module;
}
#endif
std::unordered_map<std::string, std::vector<std::string>> collect_dependencies(const fs::path& folder) {
std::unordered_map<std::string, std::vector<std::string>> dependencies;
for (const auto& file : fs::directory_iterator(folder)) {
if (file.is_directory()) {
auto subdir_dependencies = collect_dependencies(file);
dependencies.insert(subdir_dependencies.begin(), subdir_dependencies.end());
} else if (file.path().extension() == ".dll") {
HMODULE plugin_module = load_plugin(file.path());
auto plugin_module = load_plugin(file.path());
#ifdef _WIN32
get_dependencies_t get_dependencies = (get_dependencies_t)GetProcAddress(plugin_module, "get_dependencies");
#else
get_dependencies_t get_dependencies = (get_dependencies_t)dlsym(plugin_module, "get_dependencies");
if (!get_dependencies) [[unlikely]] {
fprintf(stderr, "Failed to find get_dependencies export in plugin %s\n", file.path().filename().c_str());
exit(EINVAL);
}
#endif
std::vector<std::string> wanted_dependencies;
if (get_dependencies) {
for (const char** wanted_dependency = get_dependencies(); *wanted_dependency; ++wanted_dependency) {
Expand Down Expand Up @@ -112,11 +133,15 @@ void apply_plugins(lua_State* state, std::optional<std::unordered_set<std::strin
}
}
fs::path plugin_path = folder / plugin_name;
HMODULE plugin_module = load_plugin(plugin_path);
auto plugin_module = load_plugin(plugin_path);
#ifdef _WIN32
register_library_t register_library = (register_library_t)GetProcAddress(plugin_module, "register_library");
#else
register_library_t register_library = (register_library_t)dlsym(plugin_module, "register_library");
#endif
if (!register_library) {
wprintf(L"Invalid plugin %s (missing register_library export)\n", plugin_path.wstring().c_str());
exit(ERROR_PROC_NOT_FOUND);
exit(ERROR_NOT_FOUND);
}
register_library(state);
}
Expand Down
3 changes: 2 additions & 1 deletion plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <filesystem>
namespace fs = std::filesystem;

#include <lua.h>
#include "Luau/VM/include/lua.h"
#include <optional>

fs::path get_plugins_folder();
void apply_plugins(lua_State* state, std::optional<std::unordered_set<std::string>> plugins_to_load = std::nullopt);
5 changes: 0 additions & 5 deletions runluau-build-template/.rc

This file was deleted.

22 changes: 0 additions & 22 deletions runluau-build-template/dllloader.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions runluau-build-template/dllloader.h

This file was deleted.

Loading