Skip to content

Commit fdfd5d5

Browse files
authored
Tagged userdata headers (#262)
Closes #261 by creating a `userdatas.h` header file under the Runtime folder, and switching the `Duration` and `Instant` userdatas to be tagged.
1 parent b626588 commit fdfd5d5

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

Sources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ target_sources(Lute.Runtime PRIVATE
44
runtime/include/lute/require.h
55
runtime/include/lute/requireutils.h
66
runtime/include/lute/runtime.h
7+
runtime/include/lute/userdatas.h
78

89
runtime/src/options.cpp
910
runtime/src/ref.cpp

luau/src/luau.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "Luau/ToString.h"
99
#include "Luau/Compiler.h"
1010

11+
#include "lute/userdatas.h"
12+
13+
1114
#include "lua.h"
1215
#include "lualib.h"
1316
#include <cstddef>
@@ -1707,7 +1710,7 @@ struct AstSerialize : public Luau::AstVisitor
17071710
node->type->visit(this);
17081711
lua_setfield(L, -2, "type");
17091712

1710-
serializeToken(Luau::Position{node->location.end.line, node->location.end.column -1}, ")");
1713+
serializeToken(Luau::Position{node->location.end.line, node->location.end.column - 1}, ")");
17111714
lua_setfield(L, -2, "closeParens");
17121715
}
17131716

@@ -2190,7 +2193,7 @@ int compile_luau(lua_State* L)
21902193

21912194
std::string bytecode = Luau::compile(std::string(source, source_size), opts);
21922195

2193-
std::string* userdata = static_cast<std::string*>(lua_newuserdata(L, sizeof(std::string)));
2196+
std::string* userdata = static_cast<std::string*>(lua_newuserdatatagged(L, sizeof(std::string), kCompilerResultTag));
21942197

21952198
new (userdata) std::string(std::move(bytecode));
21962199

runtime/include/lute/userdatas.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
const int kDurationTag = 1;
4+
const int kInstantTag = 2;
5+
const int kCompilerResultTag = 3;

time/include/lute/time.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ int luaopen_time(lua_State* L);
99
// open the library as a table on top of the stack
1010
int luteopen_time(lua_State* L);
1111

12-
static const int kDurationTag = 2;
13-
static const int kInstantTag = 1;
14-
1512
static const char kInstantType[] = "instant";
1613
static const char kDurationType[] = "duration";
1714
static const char kDurationLibraryIdentifier[] = "duration";

time/src/time.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "lute/time.h"
22
#include "lua.h"
33
#include "lualib.h"
4+
#include "lute/userdatas.h"
45
#include "uv.h"
56

67
#include <cmath>

0 commit comments

Comments
 (0)