Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ if (LUAU_BUILD_SHARED)
add_library(Luau.Analysis SHARED)
add_library(Luau.CodeGen SHARED)
add_library(Luau.VM SHARED)
add_library(Luau.Executor SHARED)
add_library(Luau.Require SHARED)
add_library(isocline SHARED)
else()
Expand All @@ -75,6 +76,7 @@ else()
add_library(Luau.Analysis STATIC)
add_library(Luau.CodeGen STATIC)
add_library(Luau.VM STATIC)
add_library(Luau.Executor STATIC)
add_library(Luau.Require STATIC)
add_library(isocline STATIC)
endif()
Expand Down Expand Up @@ -161,6 +163,12 @@ target_compile_features(Luau.VM PRIVATE cxx_std_17)
target_include_directories(Luau.VM PUBLIC VM/include "${PACKAGE_INCLUDE_DIR}")
target_link_libraries(Luau.VM PUBLIC Luau.Common)

# ServerLua: per-script execution engine shared with the script host
target_compile_features(Luau.Executor PUBLIC cxx_std_17)
target_include_directories(Luau.Executor PUBLIC Executor/include)
target_link_libraries(Luau.Executor PUBLIC Luau.VM)
target_link_libraries(Luau.Executor PRIVATE Luau.VM.Internals)

target_compile_features(Luau.Require PUBLIC cxx_std_17)
target_include_directories(Luau.Require PUBLIC Require/include)
target_link_libraries(Luau.Require PUBLIC Luau.Config Luau.VM)
Expand Down Expand Up @@ -219,6 +227,7 @@ target_compile_options(Luau.CLI.lib PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.LSLBuiltins PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.CodeGen PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.VM PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Executor PRIVATE ${LUAU_OPTIONS})
target_compile_options(isocline PRIVATE ${LUAU_OPTIONS} ${ISOCLINE_OPTIONS})

if(LUAU_EXTERN_C)
Expand Down Expand Up @@ -345,7 +354,7 @@ if(LUAU_BUILD_TESTS)
target_compile_definitions(Luau.Conformance PRIVATE DOCTEST_CONFIG_DOUBLE_STRINGIFY DOCTEST_CONFIG_USE_STD_HEADERS)
target_include_directories(Luau.Conformance PRIVATE extern VM/src "${PACKAGE_INCLUDE_DIR}")
target_link_directories(Luau.Conformance PRIVATE "${PACKAGE_LIB_DIR}")
target_link_libraries(Luau.Conformance PRIVATE Luau.Analysis Luau.Bytecode Luau.Inliner Luau.Compiler Luau.CodeGen Luau.VM Luau.LSLBuiltins "${TAILSLIDE_LIBRARY}")
target_link_libraries(Luau.Conformance PRIVATE Luau.Analysis Luau.Bytecode Luau.Inliner Luau.Compiler Luau.CodeGen Luau.VM Luau.Executor Luau.LSLBuiltins "${TAILSLIDE_LIBRARY}")

if(CMAKE_SYSTEM_NAME MATCHES "Android|iOS")
set(LUAU_CONFORMANCE_SOURCE_DIR "Client/Luau/tests/conformance")
Expand Down
137 changes: 137 additions & 0 deletions Executor/include/Luau/ByteStream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// ServerLua: little-endian bytestream primitives for the wrappers we place
// around ares-serialized state. I regret some of my design decisions here
// and this probably should not need to be part of the public API.
#pragma once

#include <cstdint>
#include <cstring>
#include <string>

namespace Luau
{
namespace Executor
{

struct ByteWriter
{
std::string& out;

void writeU8(uint8_t value) { out.push_back((char)value); }

void writeU32(uint32_t value)
{
for (int i = 0; i < 4; ++i)
writeU8((uint8_t)(value >> (i * 8)));
}

void writeS32(int32_t value) { writeU32((uint32_t)value); }

void writeU64(uint64_t value)
{
writeU32((uint32_t)value);
writeU32((uint32_t)(value >> 32));
}

void writeF32(float value)
{
uint32_t rep;
memcpy(&rep, &value, sizeof(rep));
writeU32(rep);
}

void writeF64(double value)
{
uint64_t rep;
memcpy(&rep, &value, sizeof(rep));
writeU64(rep);
}

void writeBytes(const char* data, size_t len) { out.append(data, len); }

// Length-prefixed, so it round-trips embedded nulls
void writeString(const char* data, size_t len)
{
writeU32((uint32_t)len);
writeBytes(data, len);
}

void writeString(const std::string& value) { writeString(value.data(), value.size()); }
};

struct ByteReader
{
const char* data;
size_t remaining;

bool readBytes(void* dest, size_t len)
{
if (len > remaining)
return false;
memcpy(dest, data, len);
data += len;
remaining -= len;
return true;
}

bool readU8(uint8_t& value) { return readBytes(&value, sizeof(value)); }

bool readU32(uint32_t& value)
{
uint8_t buf[4];
if (!readBytes(buf, sizeof(buf)))
return false;
value = (uint32_t)buf[0] | ((uint32_t)buf[1] << 8) | ((uint32_t)buf[2] << 16) | ((uint32_t)buf[3] << 24);
return true;
}

bool readS32(int32_t& value)
{
uint32_t rep;
if (!readU32(rep))
return false;
value = (int32_t)rep;
return true;
}

bool readU64(uint64_t& value)
{
uint32_t low;
uint32_t high;
if (!readU32(low) || !readU32(high))
return false;
value = (uint64_t)low | ((uint64_t)high << 32);
return true;
}

bool readF32(float& value)
{
uint32_t rep;
if (!readU32(rep))
return false;
memcpy(&value, &rep, sizeof(value));
return true;
}

bool readF64(double& value)
{
uint64_t rep;
if (!readU64(rep))
return false;
memcpy(&value, &rep, sizeof(value));
return true;
}

bool readString(std::string& value)
{
uint32_t len;
if (!readU32(len) || len > remaining)
return false;
value.assign(data, len);
data += len;
remaining -= len;
return true;
}
};

} // namespace Executor
} // namespace Luau
Loading
Loading