-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathglue.cpp
More file actions
56 lines (47 loc) · 1.27 KB
/
Copy pathglue.cpp
File metadata and controls
56 lines (47 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <string.h>
#include <stdlib.h>
#include "external/luau/Common/include/Luau/Common.h"
#include "external/luau/VM/include/lua.h"
static int csharp_trampoline(lua_State* L)
{
void* ptr = lua_tolightuserdata(L, lua_upvalueindex(1));
typedef int(*ManagedCallback)(lua_State*);
ManagedCallback fn = (ManagedCallback)ptr;
int result = fn(L);
// Catch the error.
if (result == -1)
lua_error(L);
return result;
}
extern "C"
{
void luau_free(void* ptr)
{
free(ptr);
}
void luau_setfflag(const char* name, int value)
{
for (Luau::FValue<bool>* flag = Luau::FValue<bool>::list; flag; flag = flag->next)
{
if (strcmp(flag->name, name) == 0)
{
flag->value = (bool)value;
return;
}
}
}
int luau_getfflag(const char* name)
{
for (Luau::FValue<bool>* flag = Luau::FValue<bool>::list; flag; flag = flag->next)
{
if (strcmp(flag->name, name) == 0)
return flag->value;
}
return -1;
}
void luau_pushcsharpfunc(lua_State* L, void* fnPtr)
{
lua_pushlightuserdata(L, fnPtr);
lua_pushcclosurek(L, csharp_trampoline, "luauinterop", 1, nullptr);
}
}