-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathLuaBind.CustomType.DataSet.pas
129 lines (110 loc) · 2.89 KB
/
LuaBind.CustomType.DataSet.pas
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
unit LuaBind.CustomType.DataSet;
interface
uses
Data.DB,
LuaBind;
type
TLuaDataSetExposerLibraries = class(TInterfacedObject, ILuaLibraryLoader)
public
procedure Execute(ALuaEngine: TLuaEngine);
end;
procedure ExposeDataSet(ALuaEngine: TLuaEngine; ADataSet: TDataSet; AVariableName: AnsiString);
implementation
uses LuaBind.Intf;
function _dataset_eof(L: plua_state): Integer; cdecl;
var
ds: TDataSet;
s : ansistring;
begin
s := lua_typename(L, lua_type(L, - 1));
assert(lua_islightuserdata(L, - 1));
ds := TDataSet(lua_topointer(L, - 1));
if ds.Eof then
lua_pushboolean(L, 1)
else
lua_pushboolean(L, 0);
Result := 1;
end;
function _dataset_move_next(L: plua_state): Integer; cdecl;
var
ds: TDataSet;
begin
assert(lua_islightuserdata(L, - 1));
ds := TDataSet(lua_topointer(L, - 1));
ds.Next;
Result := 0;
end;
function _dataset_field_by_name(L: plua_state): Integer; cdecl;
var
fieldname: AnsiString;
ds : TDataSet;
sdata : AnsiString;
begin
assert(lua_isstring(L, - 1) = 1);
assert(lua_islightuserdata(L, - 2));
fieldname := lua_tostring(L, - 1);
lua_pop(L, 1);
ds := TDataSet(lua_topointer(L, - 1));
lua_pop(L, 1);
sdata := ds.FieldByName(String(fieldname)).AsAnsiString;
lua_pushstring(L, pansichar(sdata));
Result := 1;
end;
function _dataset_close(L: plua_state): Integer; cdecl;
var
ds: TDataSet;
begin
assert(lua_islightuserdata(L, - 1));
ds := TDataSet(lua_topointer(L, - 1));
ds.Close;
Result := 0;
end;
function _dataset_first(L: plua_state): Integer; cdecl;
var
ds: TDataSet;
begin
assert(lua_islightuserdata(L, - 1));
ds := TDataSet(lua_topointer(L, - 1));
ds.First;
Result := 0;
end;
function _dataset_is_open(L: plua_state): Integer; cdecl;
var
ds: TDataSet;
o : Integer;
begin
assert(lua_islightuserdata(L, - 1));
ds := TDataSet(lua_topointer(L, - 1));
if ds.State = dsInactive then
o := 0
else
o := 1;
lua_pushboolean(L, o);
Result := 1;
end;
function _dataset_open(L: plua_state): Integer; cdecl;
var
ds: TDataSet;
begin
assert(lua_islightuserdata(L, - 1));
ds := TDataSet(lua_topointer(L, - 1));
ds.Open;
Result := 0;
end;
procedure ExposeDataSet(ALuaEngine: TLuaEngine; ADataSet: TDataSet; AVariableName: AnsiString);
begin
ALuaEngine.DeclareGlobalLightUserData(AVariableName, ADataSet);
end;
{ TLuaDataSetExportlibraries }
procedure TLuaDataSetExposerLibraries.Execute(ALuaEngine: TLuaEngine);
begin
ALuaEngine.
DeclareGlobalFunction('_dataset_eof', @_dataset_eof).
DeclareGlobalFunction('_dataset_move_next', @_dataset_move_next).
DeclareGlobalFunction('_dataset_field_by_name', @_dataset_field_by_name).
DeclareGlobalFunction('_dataset_first', @_dataset_first).
DeclareGlobalFunction('_dataset_is_open', @_dataset_is_open).
DeclareGlobalFunction('_dataset_open', @_dataset_open).
DeclareGlobalFunction('_dataset_close', @_dataset_close);
end;
end.