--- a/hedgewars/uScript.pas Tue Jan 21 11:48:43 2014 +0400
+++ b/hedgewars/uScript.pas Tue Jan 21 15:56:52 2014 +0100
@@ -241,30 +241,66 @@
function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl;
var i : integer;
begin
- for i:= 1 to lua_gettop(L) do
- GameFlags := GameFlags or LongWord(lua_tointeger(L, i));
- ScriptSetInteger('GameFlags', GameFlags);
+ if lua_gettop(L) = 0 then
+ begin
+ LuaParameterCountError('EnableGameFlags', '', lua_gettop(L));
+ lua_pushnil(L);
+ end
+ else
+ begin
+ for i:= 1 to lua_gettop(L) do
+ GameFlags := GameFlags or LongWord(lua_tointeger(L, i));
+ ScriptSetInteger('GameFlags', GameFlags);
+ end;
lc_enablegameflags:= 0;
end;
function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl;
var i : integer;
begin
- for i:= 1 to lua_gettop(L) do
- GameFlags := GameFlags and not(LongWord(lua_tointeger(L, i)));
- ScriptSetInteger('GameFlags', GameFlags);
+ if lua_gettop(L) = 0 then
+ begin
+ LuaParameterCountError('DisableGameFlags', '', lua_gettop(L));
+ lua_pushnil(L);
+ end
+ else
+ begin
+ for i:= 1 to lua_gettop(L) do
+ GameFlags := GameFlags and not(LongWord(lua_tointeger(L, i)));
+ ScriptSetInteger('GameFlags', GameFlags);
+ end;
lc_disablegameflags:= 0;
end;
function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl;
begin
- // Silence hint
- L:= L;
- GameFlags:= 0;
- ScriptSetInteger('GameFlags', GameFlags);
+ if lua_gettop(L) <> 0 then
+ begin
+ LuaParameterCountError('ClearGameFlags', '', lua_gettop(L));
+ lua_pushnil(L);
+ end
+ else
+ begin
+ GameFlags:= 0;
+ ScriptSetInteger('GameFlags', GameFlags);
+ end;
lc_cleargameflags:= 0;
end;
+function lc_getgameflag(L : Plua_State) : LongInt; Cdecl;
+begin
+ if lua_gettop(L) <> 1 then
+ begin
+ LuaParameterCountError('GetGameFlag', 'gameflag', lua_gettop(L));
+ lua_pushnil(L);
+ end
+ else
+ begin
+ lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0));
+ end;
+ lc_getgameflag:= 1;
+end;
+
function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
begin
if lua_gettop(L) = 1 then
@@ -2559,6 +2595,7 @@
lua_register(luaState, _P'EnableGameFlags', @lc_enablegameflags);
lua_register(luaState, _P'DisableGameFlags', @lc_disablegameflags);
lua_register(luaState, _P'ClearGameFlags', @lc_cleargameflags);
+lua_register(luaState, _P'GetGameFlag', @lc_getgameflag);
lua_register(luaState, _P'DeleteGear', @lc_deletegear);
lua_register(luaState, _P'AddVisualGear', @lc_addvisualgear);
lua_register(luaState, _P'DeleteVisualGear', @lc_deletevisualgear);