hedgewars/uScript.pas
branchqmlfrontend
changeset 11544 b69f5f22a3ba
parent 11532 bf86c6cb9341
child 11561 254333210cc8
equal deleted inserted replaced
11481:caa1e84c3ac2 11544:b69f5f22a3ba
    21 unit uScript;
    21 unit uScript;
    22 (*
    22 (*
    23  * This unit defines, implements and registers functions and
    23  * This unit defines, implements and registers functions and
    24  * variables/constants bindings for usage in Lua scripts.
    24  * variables/constants bindings for usage in Lua scripts.
    25  *
    25  *
    26  * Please keep http://code.google.com/p/hedgewars/wiki/LuaAPI up to date!
    26  * Please keep http://hedgewars.org/kb/LuaAPI up to date!
    27  *
    27  *
    28  * Note: If you add a new function, make sure to test if _all_ parameters
    28  * Note: If you add a new function, make sure to test if _all_ parameters
    29  *       work as intended! (Especially conversions errors can sneak in
    29  *       work as intended! (Especially conversions errors can sneak in
    30  *       unnoticed and render the parameter useless!)
    30  *       unnoticed and render the parameter useless!)
    31  *)
    31  *)
   436         at:= LuaToAmmoTypeOrd(L, 1, call, params);
   436         at:= LuaToAmmoTypeOrd(L, 1, call, params);
   437         if at >= 0 then
   437         if at >= 0 then
   438             ParseCommand('setweap ' + char(at), true, true);
   438             ParseCommand('setweap ' + char(at), true, true);
   439         end;
   439         end;
   440     lc_setweapon:= 0;
   440     lc_setweapon:= 0;
       
   441 end;
       
   442 
       
   443 // enable/disable cinematic effects
       
   444 function lc_setcinematicmode(L : Plua_State) : LongInt; Cdecl;
       
   445 const
       
   446     call = 'SetCinematicMode';
       
   447     params = 'enable';
       
   448 begin
       
   449     if (CheckLuaParamCount(L, 1, call, params)) then
       
   450         begin
       
   451         CinematicScript:= lua_toboolean(L, 1);
       
   452         end;
       
   453     lc_setcinematicmode:= 0;
   441 end;
   454 end;
   442 
   455 
   443 // no parameter means reset to default (and 0 means unlimited)
   456 // no parameter means reset to default (and 0 means unlimited)
   444 function lc_setmaxbuilddistance(L : Plua_State) : LongInt; Cdecl;
   457 function lc_setmaxbuilddistance(L : Plua_State) : LongInt; Cdecl;
   445 var np: LongInt;
   458 var np: LongInt;
  3095     spr: TSprite;
  3108     spr: TSprite;
  3096     mg : TMapGen;
  3109     mg : TMapGen;
  3097 begin
  3110 begin
  3098 // initialize lua
  3111 // initialize lua
  3099 luaState:= lua_open;
  3112 luaState:= lua_open;
  3100 TryDo(luaState <> nil, 'lua_open failed', true);
  3113 if checkFails(luaState <> nil, 'lua_open failed', true) then exit;
  3101 
  3114 
  3102 // open internal libraries
  3115 // open internal libraries
  3103 luaopen_base(luaState);
  3116 luaopen_base(luaState);
  3104 luaopen_string(luaState);
  3117 luaopen_string(luaState);
  3105 luaopen_math(luaState);
  3118 luaopen_math(luaState);
  3338 lua_register(luaState, _P'GetGravity', @lc_getgravity);
  3351 lua_register(luaState, _P'GetGravity', @lc_getgravity);
  3339 lua_register(luaState, _P'SetGravity', @lc_setgravity);
  3352 lua_register(luaState, _P'SetGravity', @lc_setgravity);
  3340 lua_register(luaState, _P'SetWaterLine', @lc_setwaterline);
  3353 lua_register(luaState, _P'SetWaterLine', @lc_setwaterline);
  3341 lua_register(luaState, _P'SetNextWeapon', @lc_setnextweapon);
  3354 lua_register(luaState, _P'SetNextWeapon', @lc_setnextweapon);
  3342 lua_register(luaState, _P'SetWeapon', @lc_setweapon);
  3355 lua_register(luaState, _P'SetWeapon', @lc_setweapon);
       
  3356 lua_register(luaState, _P'SetCinematicMode', @lc_setcinematicmode);
  3343 lua_register(luaState, _P'SetMaxBuildDistance', @lc_setmaxbuilddistance);
  3357 lua_register(luaState, _P'SetMaxBuildDistance', @lc_setmaxbuilddistance);
  3344 // drawn map functions
  3358 // drawn map functions
  3345 lua_register(luaState, _P'AddPoint', @lc_addPoint);
  3359 lua_register(luaState, _P'AddPoint', @lc_addPoint);
  3346 lua_register(luaState, _P'FlushPoints', @lc_flushPoints);
  3360 lua_register(luaState, _P'FlushPoints', @lc_flushPoints);
  3347 
  3361