103 procedure ScriptPrepareAmmoStore; forward; |
103 procedure ScriptPrepareAmmoStore; forward; |
104 procedure ScriptApplyAmmoStore; forward; |
104 procedure ScriptApplyAmmoStore; forward; |
105 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward; |
105 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward; |
106 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward; |
106 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward; |
107 |
107 |
|
108 var LuaDebugInfo: lua_Debug; |
|
109 |
|
110 function LuaUpdateDebugInfo(): Boolean; |
|
111 begin |
|
112 FillChar(LuaDebugInfo, sizeof(LuaDebugInfo), 0); |
|
113 |
|
114 if lua_getstack(luaState, 1, @LuaDebugInfo) = 0 then |
|
115 exit(false); // stack not deep enough |
|
116 |
|
117 // get source name and line count |
|
118 lua_getinfo(luaState, 'Sl', @LuaDebugInfo); |
|
119 exit(true); |
|
120 end; |
|
121 |
108 procedure LuaError(s: shortstring); |
122 procedure LuaError(s: shortstring); |
109 begin |
123 var src: shortstring; |
110 s:= 'Lua-script error: ' + s; |
124 const |
|
125 maxsrclen = 20; |
|
126 begin |
|
127 if LuaUpdateDebugInfo() then |
|
128 begin |
|
129 src:= StrPas(LuaDebugInfo.source); |
|
130 s:= 'LUA ERROR [ ... ' |
|
131 + copy(src, Length(src) - maxsrclen, maxsrclen - 3) + ':' |
|
132 + inttostr(LuaDebugInfo.currentLine) + ']: ' + s; |
|
133 end |
|
134 else |
|
135 s:= 'LUA ERROR: ' + s; |
111 WriteLnToConsole(s); |
136 WriteLnToConsole(s); |
112 AddChatString(#5 + s); |
137 AddChatString(#5 + s); |
113 if cTestLua then |
138 if cTestLua then |
114 halt(rtnTestLuaErr); |
139 halt(rtnTestLuaErr); |
115 end; |
140 end; |
116 |
141 |
117 procedure LuaCallError(error, call, paramsyntax: shortstring); |
142 procedure LuaCallError(error, call, paramsyntax: shortstring); |
118 begin |
143 begin |
119 LuaError(call + ': ' + error + ' function syntax: ' + call + ' ( ' + paramsyntax + ' )'); |
144 LuaError(call + ': ' + error); |
|
145 LuaError('-- SYNTAX: ' + call + ' ( ' + paramsyntax + ' )'); |
120 end; |
146 end; |
121 |
147 |
122 procedure LuaParameterCountError(expected, call, paramsyntax: shortstring; wrongcount: LongInt); inline; |
148 procedure LuaParameterCountError(expected, call, paramsyntax: shortstring; wrongcount: LongInt); inline; |
123 begin |
149 begin |
124 // TODO: i18n? |
150 // TODO: i18n? |