This repository was archived by the owner on Apr 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua-user_data.adb
More file actions
68 lines (59 loc) · 1.81 KB
/
Copy pathlua-user_data.adb
File metadata and controls
68 lines (59 loc) · 1.81 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
57
58
59
60
61
62
63
64
65
66
67
68
-- Lua userdata handling
package body Lua.User_Data is
use type System.Address;
package C_Bindings is
function New_User_Data
(State : Lua.State_t;
Size : Lua.IC.size_t) return System.Address;
pragma Import (C, New_User_Data, "lua_newuserdata");
function To_User_Data
(State : Lua.State_t;
Index : Lua.Integer_t) return System.Address;
pragma Import (C, To_User_Data, "lua_touserdata");
end C_Bindings;
procedure Register (State : Lua.State_t) is
Dummy : Boolean;
begin
Lua.Lib.Open_Library (State, Class_Name, Method_Table, 0);
Dummy := Lua.Lib.New_Metatable (State, Class_Name);
if not Dummy then
return;
end if;
Lua.Lib.Open_Library (State, "", Meta_Table, 0);
Lua.Push_String (State, "__index");
Lua.Push_Value (State, -3);
Lua.Raw_Set (State, -3);
Lua.Push_String (State, "__metatable");
Lua.Push_Value (State, -3);
Lua.Raw_Set (State, -3);
Lua.Pop (State, 1);
end Register;
procedure Push
(State : Lua.State_t;
Item : User_Data_t)
is
UD_Access : User_Data_Access_t;
Error : Lua.Error_t;
begin
UD_Access := User_Data_Access_t
(Convert.To_Pointer
(C_Bindings.New_User_Data
(State => State,
Size => Lua.IC.size_t (User_Data_t'Size / System.Storage_Unit))));
UD_Access.all := Item;
Lua.Push_String (State, Class_Name);
Lua.Raw_Get (State, Lua.Registry_Index);
Error := Lua.Set_Metatable (State, -2);
if Error /= Lua.Lua_Error_None then
return;
end if;
end Push;
function Get
(State : Lua.State_t;
Index : Integer := 1) return User_Data_t
is
Address : constant System.Address := C_Bindings.To_User_Data (State, Lua.Integer_t (Index));
begin
return Convert.To_Pointer (Address).all;
end Get;
end Lua.User_Data;