我仍然对将Delphi userdata注册到Lua感到困惑.教我学习实现日期(时间)类型的原则.
开头这个类型应该有Lua可以访问的三个函数:
new函数来创建此类型的变量.getdate功能.setdate功能.最后这个小Lua脚本应该工作:
DT = DateTime.new()
DT:setdate(1, 1, 2011)
day, month, year = DT:getdate()
print("Day: " .. day .. " Month: " .. month .." Year: " .. year)
Run Code Online (Sandbox Code Playgroud)
我试图自己实现它(使用Lua中的Programming),但是我收到一条错误说:_attempt to index global 'DT' (a userdata value)_第2行.我可能在用户数据注册时出错了但我找不到错误.
我希望你能帮助我找到它,这是我已经得到的:
Const
MetaPosDateTime = 'DateTime';
Type
tLuaDateTime = tDateTime;
pLuaDateTime = ^tLuaDateTime;
Function newdatetime(aState : pLua_State) : longint; cdecl;
Var
NewData : pLuaDateTime;
Begin
Result := 0; …Run Code Online (Sandbox Code Playgroud)