From: fgsfds Date: Mon, 31 Jul 2017 19:29:07 +0000 (+0300) Subject: remove scripts X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=commitdiff_plain;h=921c3b45ee6dd3b39307f4d1d6c05ab1c137bd49 remove scripts --- diff --git a/src/game/Doom2DF.dpr b/src/game/Doom2DF.dpr index 17f17b7..3fbd829 100644 --- a/src/game/Doom2DF.dpr +++ b/src/game/Doom2DF.dpr @@ -106,10 +106,7 @@ uses g_language in 'g_language.pas', ImagingTypes, Imaging, - ImagingUtility, - lua in '../lib/lua/lua.pas', - lualib in '../lib/lua/lualib.pas', - lauxlib in '../lib/lua/lauxlib.pas'; + ImagingUtility; {$IFDEF WINDOWS} {$R *.res} diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 9166021..6a11291 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -20,7 +20,7 @@ interface uses g_basic, g_player, e_graphics, Classes, g_res_downloader, - SysUtils, g_sound, g_gui, g_scripts, MAPSTRUCT, wadreader, md5; + SysUtils, g_sound, g_gui, MAPSTRUCT, wadreader, md5; type TGameSettings = record @@ -1104,9 +1104,6 @@ begin g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False); g_Menu_Init(); - - g_Scripts_Init(); - g_Scripts_Load('game.conprint("Scripts Init")'); gMusic := TMusic.Create(); gMusic.SetByName('MUSIC_MENU'); diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 9cc29e3..9f9465b 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -134,7 +134,7 @@ uses GL, GLExt, g_weapons, g_game, g_sound, e_sound, CONFIG, g_options, MAPREADER, g_triggers, g_player, MAPDEF, Math, g_monsters, g_saveload, g_language, g_netmsg, - utils, sfs, g_scripts, + utils, sfs, ImagingTypes, Imaging, ImagingUtility, ImagingGif, ImagingNetworkGraphics; @@ -488,12 +488,11 @@ function CreateAnimTexture(RecName: String; Map: string; log: Boolean): Integer; var WAD: TWADFile; TextureWAD: PChar = nil; - ttw: PChar = nil; TextData: Pointer = nil; TextureData: Pointer = nil; cfg: TConfig = nil; WADName: String; - ResLength, rrl: Integer; + ResLength: Integer; TextureResource: String; _width, _height, _framecount, _speed: Integer; _backanimation: Boolean; @@ -920,9 +919,9 @@ var DoorPanel: Integer; ShotPanel: Integer; end; - FileName, mapResName, s, TexName, ScrStr: String; - Data, ScrText: Pointer; - Len, ScrLen: Integer; + FileName, mapResName, s, TexName: String; + Data: Pointer; + Len: Integer; ok, isAnim, trigRef: Boolean; CurTex, ntn: Integer; begin @@ -953,18 +952,6 @@ begin WAD.Free(); Exit; end; - - // try to load the map script - g_Scripts_Reset(RESET_MAP); - ScrText := nil; - ScrLen := 0; - if WAD.GetResource('SCRIPTS/'+mapResName, ScrText, ScrLen) then - begin - g_Console_Add('SCRIPT: Found script for this map. Loading...'); - SetString(ScrStr, ScrText, ScrLen); - g_Scripts_Load(ScrStr); - FreeMem(ScrText); - end; WAD.Free(); diff --git a/src/game/g_scriptprocs.pas b/src/game/g_scriptprocs.pas deleted file mode 100644 index 262ba33..0000000 --- a/src/game/g_scriptprocs.pas +++ /dev/null @@ -1,1257 +0,0 @@ -(* Copyright (C) DooM 2D:Forever Developers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - *) -{$MODE DELPHI} -unit g_scriptprocs; - -interface - -uses - g_scripts; - -function SP_Lua_ConPrint(L: PScriptContext): Integer; cdecl; -function SP_Lua_PlaySound(L: PScriptContext): Integer; cdecl; -function SP_Lua_Message(L: PScriptContext): Integer; cdecl; -function SP_Lua_GetGameMode(L: PScriptContext): Integer; cdecl; -function SP_Lua_GetGameType(L: PScriptContext): Integer; cdecl; -function SP_Lua_GetTime(L: PScriptContext): Integer; cdecl; - -function SP_Lua_PlayerGetKeys(L: PScriptContext): Integer; cdecl; -function SP_Lua_PlayerGetArmor(L: PScriptContext): Integer; cdecl; -function SP_Lua_PlayerGetTeam(L: PScriptContext): Integer; cdecl; -function SP_Lua_PlayerGetScore(L: PScriptContext): Integer; cdecl; -function SP_Lua_PlayerGetName(L: PScriptContext): Integer; cdecl; - -function SP_Lua_ActorGetPos(L: PScriptContext): Integer; cdecl; -function SP_Lua_ActorGetHealth(L: PScriptContext): Integer; cdecl; -function SP_Lua_ActorGetState(L: PScriptContext): Integer; cdecl; -function SP_Lua_ActorGetType(L: PScriptContext): Integer; cdecl; -function SP_Lua_ActorNearest(L: PScriptContext): Integer; cdecl; -function SP_Lua_ActorFarthest(L: PScriptContext): Integer; cdecl; -function SP_Lua_ActorDamage(L: PScriptContext): Integer; cdecl; -function SP_Lua_ActorTeleport(L: PScriptContext): Integer; cdecl; -function SP_Lua_ActorPush(L: PScriptContext): Integer; cdecl; - -function SP_Lua_TriggerActivate(L: PScriptContext): Integer; cdecl; -function SP_Lua_TriggerGetEnabled(L: PScriptContext): Integer; cdecl; -function SP_Lua_TriggerSetEnabled(L: PScriptContext): Integer; cdecl; -function SP_Lua_TriggerGetPos(L: PScriptContext): Integer; cdecl; -function SP_Lua_TriggerSetPos(L: PScriptContext): Integer; cdecl; - -function SP_Lua_PanelGetType(L: PScriptContext): Integer; cdecl; -function SP_Lua_PanelGetPos(L: PScriptContext): Integer; cdecl; -function SP_Lua_PanelGetSize(L: PScriptContext): Integer; cdecl; -function SP_Lua_PanelSetPos(L: PScriptContext): Integer; cdecl; -function SP_Lua_PanelSwitchTexture(L: PScriptContext): Integer; cdecl; - -function SP_Lua_DoorGetState(L: PScriptContext): Integer; cdecl; -function SP_Lua_DoorOpen(L: PScriptContext): Integer; cdecl; -function SP_Lua_DoorClose(L: PScriptContext): Integer; cdecl; -function SP_Lua_DoorToggle(L: PScriptContext): Integer; cdecl; -function SP_Lua_DoorCloseTrap(L: PScriptContext): Integer; cdecl; -function SP_Lua_LiftSetDir(L: PScriptContext): Integer; cdecl; -function SP_Lua_LiftGetDir(L: PScriptContext): Integer; cdecl; - -function SP_Lua_SpawnShot(L: PScriptContext): Integer; cdecl; -function SP_Lua_SpawnEffect(L: PScriptContext): Integer; cdecl; -function SP_Lua_SpawnMonster(L: PScriptContext): Integer; cdecl; -function SP_Lua_SpawnItem(L: PScriptContext): Integer; cdecl; - -implementation - -uses - lua, lauxlib, - g_player, g_map, Math, g_gfx, g_game, g_textures, - g_console, g_monsters, g_items, g_phys, g_weapons, - g_main, SysUtils, e_log, g_language, g_basic, - g_options, g_net, g_netmsg, g_triggers, g_panel, - g_sound, MAPDEF; - -function CheckArgs(L: PScriptContext; MinArgs: Integer; Error: Boolean = True): Boolean; inline; -begin - Result := True; - if lua_gettop(L) < MinArgs then - begin - if Error then g_Console_Add('SCRIPT: ERROR: expected at least ' + IntToStr(MinArgs) + ' argument(s)'); - Result := False; - end; -end; - -// system // - -function SP_Lua_ConPrint(L: PScriptContext): Integer; cdecl; -// game.con_print(text) -const - MINARGS = 1; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then Exit; - g_Console_Add(luaL_checkstring(L, 1)); -end; - -function SP_Lua_Message(L: PScriptContext): Integer; cdecl; -// game.message(type, text, channel[, uid=0, timeout=144]) -const - MINARGS = 3; -var - MText: string; - MChan, MKind, MID, MTime: Integer; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - MKind := luaL_checkinteger(L, 1); - MText := luaL_checkstring(L, 2); - MChan := luaL_checkinteger(L, 3); - - MID := lua_tointeger(L, 4); - MTime := lua_tointeger(L, 5); - if MTime = 0 then MTime := 144; - - tr_Message(MKind, MText, MChan, MTime, MID); -end; - -function SP_Lua_GetGameMode(L: PScriptContext): Integer; cdecl; -// game.get_gamemode() -const - MINARGS = 0; -begin - Result := 1; - lua_pushinteger(L, gGameSettings.GameMode); -end; - -function SP_Lua_GetGameType(L: PScriptContext): Integer; cdecl; -// game.get_gametype() -const - MINARGS = 0; -begin - Result := 1; - lua_pushinteger(L, gGameSettings.GameType); -end; - -function SP_Lua_GetTime(L: PScriptContext): Integer; cdecl; -// game.get_time() -const - MINARGS = 0; -begin - Result := 1; - lua_pushinteger(L, gTime); -end; - -function SP_Lua_PlaySound(L: PScriptContext): Integer; cdecl; -// game.sound(name[positional=false, x=0, y=0]) -const - MINARGS = 1; -var - SName: string; - SPos: Boolean; - SX, SY: Integer; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - SName := luaL_checkstring(L, 1); - - SPos := lua_toboolean(L, 2); - SX := lua_tointeger(L, 3); - SY := lua_tointeger(L, 4); - - if SPos then - g_Sound_PlayExAt(SName, SX, SY) - else - g_Sound_PlayEx(SName); - - if g_Game_IsNet then - MH_SEND_Sound(SX, SY, SName, SPos); -end; - -// players // - -function SP_Lua_PlayerGetKeys(L: PScriptContext): Integer; cdecl; -// game.player_get_keys(uid) -const - MINARGS = 1; -var - UID: Integer; - P: TPlayer; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - UID := luaL_checkinteger(L, 1); - - if g_GetUIDType(UID) <> UID_PLAYER then - lua_pushnil(L) - else - begin - P := g_Player_Get(UID); - if P = nil then - begin - lua_pushnil(L); - exit; - end; - lua_pushinteger(L, P.GetKeys); - end; -end; - -function SP_Lua_PlayerGetArmor(L: PScriptContext): Integer; cdecl; -// game.player_get_armor(uid) -const - MINARGS = 1; -var - UID: Integer; - P: TPlayer; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - UID := luaL_checkinteger(L, 1); - - if g_GetUIDType(UID) <> UID_PLAYER then - lua_pushnil(L) - else - begin - P := g_Player_Get(UID); - if P = nil then - begin - lua_pushnil(L); - exit; - end; - lua_pushinteger(L, P.Armor); - end; -end; - -function SP_Lua_PlayerGetName(L: PScriptContext): Integer; cdecl; -// game.player_get_name(uid) -const - MINARGS = 1; -var - UID: Integer; - P: TPlayer; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - UID := luaL_checkinteger(L, 1); - - if g_GetUIDType(UID) <> UID_PLAYER then - lua_pushnil(L) - else - begin - P := g_Player_Get(UID); - if P = nil then - begin - lua_pushnil(L); - exit; - end; - lua_pushstring(L, P.Name); - end; -end; - -function SP_Lua_PlayerGetTeam(L: PScriptContext): Integer; cdecl; -// game.player_get_team(uid) -const - MINARGS = 1; -var - UID: Integer; - P: TPlayer; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - UID := luaL_checkinteger(L, 1); - - if g_GetUIDType(UID) <> UID_PLAYER then - lua_pushnil(L) - else - begin - P := g_Player_Get(UID); - if P = nil then - begin - lua_pushnil(L); - exit; - end; - lua_pushinteger(L, P.Team); - end; -end; - -function SP_Lua_PlayerGetScore(L: PScriptContext): Integer; cdecl; -// game.player_get_score(uid) -const - MINARGS = 1; -var - UID: Integer; - P: TPlayer; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - UID := luaL_checkinteger(L, 1); - - if g_GetUIDType(UID) <> UID_PLAYER then - lua_pushnil(L) - else - begin - P := g_Player_Get(UID); - if P = nil then - begin - lua_pushnil(L); - exit; - end; - lua_pushinteger(L, P.Frags); - end; -end; - -// actors // - -function SP_Lua_ActorGetPos(L: PScriptContext): Integer; cdecl; -// game.uid_get_pos(uid) -const - MINARGS = 1; -var - UID: Integer; - P: TPlayer; - M: TMonster; -begin - Result := 2; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - UID := luaL_checkinteger(L, 1); - - if g_GetUIDType(UID) = UID_PLAYER then - begin - P := g_Player_Get(UID); - if P = nil then - begin - lua_pushnil(L); - lua_pushnil(L); - exit; - end; - lua_pushinteger(L, P.GameX + PLAYER_RECT_CX); - lua_pushinteger(L, P.GameY + PLAYER_RECT_CY); - end - else if g_GetUIDType(UID) = UID_MONSTER then - begin - M := g_Monsters_Get(UID); - if M = nil then - begin - lua_pushnil(L); - lua_pushnil(L); - exit; - end; - lua_pushinteger(L, M.Obj.X+M.Obj.Rect.X+(M.Obj.Rect.Width div 2)); - lua_pushinteger(L, M.Obj.Y+M.Obj.Rect.Y+(M.Obj.Rect.Height div 2)); - end - else - begin - lua_pushnil(L); - lua_pushnil(L); - end; -end; - -function SP_Lua_ActorNearest(L: PScriptContext): Integer; cdecl; -// game.uid_nearest(x, y, [type=all, min, max]) -const - MINARGS = 2; -var - i, UID, AType: Integer; - X, Y, Dist, MinDist, MaxDist, FMin: Double; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - X := luaL_checkinteger(L, 1); - Y := luaL_checkinteger(L, 2); - - AType := lua_tointeger(L, 3); - MinDist := Sqr(lua_tonumber(L, 4)); - MaxDist := Sqr(lua_tonumber(L, 5)); - if MaxDist < 0.01 then MaxDist := 1e15; - if MinDist < 0.01 then MinDist := 0; - FMin := MaxDist; - UID := -1; - - if (AType in [UID_GAME, UID_PLAYER]) and (gPlayers <> nil) then - for i := 0 to High(gPlayers) do - begin - if gPlayers[i] = nil then continue; - Dist := Sqr(X - gPlayers[i].GameX) + Sqr(Y - gPlayers[i].GameY); - if (Dist > MinDist) and (Dist < FMin) then - begin - UID := gPlayers[i].UID; - FMin := Dist; - end; - end; - if (AType in [UID_GAME, UID_MONSTER]) and (gMonsters <> nil) then - for i := 0 to High(gMonsters) do - begin - if gMonsters[i] = nil then continue; - Dist := Sqr(X - gMonsters[i].GameX) + Sqr(Y - gMonsters[i].GameY); - if (Dist > MinDist) and (Dist < FMin) then - begin - UID := gMonsters[i].UID; - FMin := Dist; - end; - end; - - lua_pushinteger(L, UID); -end; - -function SP_Lua_ActorFarthest(L: PScriptContext): Integer; cdecl; -// game.uid_farthest(x, y, [type=all, min, max]) -const - MINARGS = 2; -var - i, UID, AType: Integer; - X, Y, Dist, MinDist, MaxDist, FMax: Double; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - X := luaL_checkinteger(L, 1); - Y := luaL_checkinteger(L, 2); - - AType := lua_tointeger(L, 3); - MinDist := Sqr(lua_tonumber(L, 4)); - MaxDist := Sqr(lua_tonumber(L, 5)); - if MaxDist < 0.01 then MaxDist := 1e15; - if MinDist < 0.01 then MinDist := 0; - FMax := MinDist; - UID := -1; - - if (AType in [UID_GAME, UID_PLAYER]) and (gPlayers <> nil) then - for i := 0 to High(gPlayers) do - begin - if gPlayers[i] = nil then continue; - Dist := Sqr(X - gPlayers[i].GameX) + Sqr(Y - gPlayers[i].GameY); - if (Dist < MaxDist) and (Dist > FMax) then - begin - UID := gPlayers[i].UID; - FMax := Dist; - end; - end; - if (AType in [UID_GAME, UID_MONSTER]) and (gMonsters <> nil) then - for i := 0 to High(gMonsters) do - begin - if gMonsters[i] = nil then continue; - Dist := Sqr(X - gMonsters[i].GameX) + Sqr(Y - gMonsters[i].GameY); - if (Dist < MaxDist) and (Dist > FMax) then - begin - UID := gMonsters[i].UID; - FMax := Dist; - end; - end; - - lua_pushinteger(L, UID); -end; - -function SP_Lua_ActorGetType(L: PScriptContext): Integer; cdecl; -// game.uid_type(uid) -const - MINARGS = 2; -var - UID, UType: Integer; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - UID := luaL_checkinteger(L, 1); - if (UID < 0) or (UID > $FFFF) then - lua_pushnil(L) - else - begin - UType := g_GetUIDType(UID); - if not (UType in [UID_PLAYER, UID_MONSTER{*, UID_ITEM*}]) then - lua_pushnil(L) - else - lua_pushinteger(L, UType); - end; -end; - -function SP_Lua_ActorDamage(L: PScriptContext): Integer; cdecl; -// game.uid_damage(uid, amount[, hit_type=hit_some, vx=0, vy=0, attacker_uid=0]) -const - MINARGS = 2; -var - UID, AUID, Dmg, Atk, VX, VY: Integer; - P: TPlayer; - M: TMonster; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - UID := luaL_checkinteger(L, 1); - Dmg := luaL_checkinteger(L, 2); - - Atk := lua_tointeger(L, 3); - VX := lua_tointeger(L, 4); - VY := lua_tointeger(L, 5); - AUID := lua_tointeger(L, 6); - - if g_GetUIDType(UID) = UID_PLAYER then - begin - P := g_Player_Get(UID); - if P = nil then exit; - if Dmg >= 0 then - P.Damage(Dmg, AUID, VX, VY, Atk) - else - P.Heal(-Dmg, False); - end - else if g_GetUIDType(UID) = UID_MONSTER then - begin - M := g_Monsters_Get(UID); - if M = nil then exit; - if Dmg >= 0 then - M.Damage(Dmg, AUID, VX, VY, Atk) - else - M.Heal(-Dmg); - end; -end; - -function SP_Lua_ActorGetHealth(L: PScriptContext): Integer; cdecl; -// game.uid_get_health(uid) -const - MINARGS = 1; -var - UID: Integer; - P: TPlayer; - M: TMonster; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - UID := luaL_checkinteger(L, 1); - - if g_GetUIDType(UID) = UID_PLAYER then - begin - P := g_Player_Get(UID); - if P = nil then - begin - lua_pushnil(L); - exit; - end; - lua_pushinteger(L, P.Health); - end - else if g_GetUIDType(UID) = UID_MONSTER then - begin - M := g_Monsters_Get(UID); - if M = nil then - begin - lua_pushnil(L); - exit; - end; - lua_pushinteger(L, M.MonsterHealth); - end - else - lua_pushnil(L); -end; - -function SP_Lua_ActorGetState(L: PScriptContext): Integer; cdecl; -// game.uid_get_state(uid) -const - MINARGS = 1; -var - UID: Integer; - P: TPlayer; - M: TMonster; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - UID := luaL_checkinteger(L, 1); - - if g_GetUIDType(UID) = UID_PLAYER then - begin - P := g_Player_Get(UID); - if P = nil then - begin - lua_pushnil(L); - exit; - end; - if P.Live then - lua_pushinteger(L, 1) - else if P.FSpectator then - lua_pushinteger(L, -1) - else - lua_pushinteger(L, 0); - end - else if g_GetUIDType(UID) = UID_MONSTER then - begin - M := g_Monsters_Get(UID); - if M = nil then - begin - lua_pushnil(L); - exit; - end; - lua_pushinteger(L, IfThen(M.Live, 1, 0)); - end - else - lua_pushnil(L); -end; - -function SP_Lua_ActorTeleport(L: PScriptContext): Integer; cdecl; -// game.uid_teleport(uid, to_x, to_y[, dir=left, silent=false, d2d_like=false]) -const - MINARGS = 3; -var - D2D, NoSound: Boolean; - UID, TX, TY: Integer; - TDir: Integer; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - UID := luaL_checkinteger(L, 1); - TX := luaL_checkinteger(L, 2); - TY := luaL_checkinteger(L, 3); - - TDir := lua_tointeger(L, 4) mod 2; - NoSound := lua_toboolean(L, 5); - D2D := lua_toboolean(L, 6); - - tr_Teleport(UID, TX, TY, TDir, NoSound, D2D); -end; - -function SP_Lua_ActorPush(L: PScriptContext): Integer; cdecl; -// game.uid_push(uid, vx, vy[, reset_vel=false]) -const - MINARGS = 3; -var - ResetVel: Boolean; - UID, VX, VY: Integer; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - UID := luaL_checkinteger(L, 1); - VX := luaL_checkinteger(L, 2); - VY := luaL_checkinteger(L, 3); - - ResetVel := lua_toboolean(L, 4); - - tr_Push(UID, VX, VY, ResetVel); -end; - -// triggers // - -function SP_Lua_TriggerSetEnabled(L: PScriptContext): Integer; cdecl; -// game.trigger_set_enabled(id, active) -const - MINARGS = 2; -var - TID: Integer; - Enabled: Boolean; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - TID := luaL_checkinteger(L, 1); - Enabled := lua_toboolean(L, 2); - - if (TID < 0) or (TID > High(gTriggers)) then exit; - if gTriggers[TID].TriggerType = TRIGGER_NONE then exit; - gTriggers[TID].Enabled := Enabled; -end; - -function SP_Lua_TriggerGetEnabled(L: PScriptContext): Integer; cdecl; -// game.trigger_get_enabled(id) -const - MINARGS = 1; -var - TID: Integer; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - TID := luaL_checkinteger(L, 1); - - if (TID < 0) or (TID > High(gTriggers)) or (gTriggers[TID].TriggerType = TRIGGER_NONE) then - lua_pushnil(L) - else - lua_pushboolean(L, gTriggers[TID].Enabled); -end; - -function SP_Lua_TriggerActivate(L: PScriptContext): Integer; cdecl; -// game.trigger_activate(id[, activate_type=custom, activator_uid=0]) -const - MINARGS = 1; -var - TID, UID: Integer; - TAct: Byte; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - TID := luaL_checkinteger(L, 1); - - TAct := lua_tointeger(L, 2); - if TAct = 0 then TAct := 255; - UID := lua_tointeger(L, 3); - - if (TID < 0) or (TID > High(gTriggers)) then exit; - if gTriggers[TID].TriggerType = TRIGGER_NONE then exit; - if ByteBool(gTriggers[TID].ActivateType and TAct) then - g_Triggers_Press(TID, TAct, UID); -end; - -function SP_Lua_TriggerGetPos(L: PScriptContext): Integer; cdecl; -// game.trigger_get_pos(id) -const - MINARGS = 1; -var - TID: Integer; -begin - Result := 2; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - TID := luaL_checkinteger(L, 1); - - if (TID < 0) or (TID > High(gTriggers)) or (gTriggers[TID].TriggerType = TRIGGER_NONE) then - begin - lua_pushnil(L); - lua_pushnil(L); - end - else - begin - lua_pushinteger(L, gTriggers[TID].X); - lua_pushinteger(L, gTriggers[TID].Y); - end; -end; - -function SP_Lua_TriggerSetPos(L: PScriptContext): Integer; cdecl; -// game.trigger_set_pos(id, x, y) -const - MINARGS = 3; -var - TID, X, Y: Integer; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - TID := luaL_checkinteger(L, 1); - X := luaL_checkinteger(L, 2); - Y := luaL_checkinteger(L, 3); - - if (TID < 0) or (TID > High(gTriggers)) then exit; - if gTriggers[TID].TriggerType in [TRIGGER_NONE, TRIGGER_SOUND] then exit; - gTriggers[TID].X := X; - gTriggers[TID].Y := Y; -end; - -// doors & panels // - -function SP_Lua_PanelGetType(L: PScriptContext): Integer; cdecl; -// game.panel_get_type(panel_id) -const - MINARGS = 1; -var - PID, WID: Integer; - Pan: PPanel; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - PID := luaL_checkinteger(L, 1); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) then - lua_pushnil(L) - else - lua_pushinteger(L, Pan^.PanelType); -end; - -function SP_Lua_PanelGetPos(L: PScriptContext): Integer; cdecl; -// game.panel_get_pos(panel_id) -const - MINARGS = 1; -var - PID, WID: Integer; - Pan: PPanel; -begin - Result := 2; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - PID := luaL_checkinteger(L, 1); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) then - begin - lua_pushnil(L); - lua_pushnil(L); - end - else - begin - lua_pushinteger(L, Pan^.X); - lua_pushinteger(L, Pan^.Y); - end; -end; - -function SP_Lua_PanelGetSize(L: PScriptContext): Integer; cdecl; -// game.panel_get_size(panel_id) -const - MINARGS = 1; -var - PID, WID: Integer; - Pan: PPanel; -begin - Result := 2; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - PID := luaL_checkinteger(L, 1); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) then - begin - lua_pushnil(L); - lua_pushnil(L); - end - else - begin - lua_pushinteger(L, Pan^.Width); - lua_pushinteger(L, Pan^.Height); - end; -end; - -function SP_Lua_PanelSwitchTexture(L: PScriptContext): Integer; cdecl; -// game.panel_switch_texture(panel_id) -const - MINARGS = 1; -var - PID, WID: Integer; - Pan: PPanel; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - PID := luaL_checkinteger(L, 1); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) then exit; - g_Map_SwitchTexture(Pan^.PanelType, WID, 0); -end; - -function SP_Lua_PanelSetPos(L: PScriptContext): Integer; cdecl; -// game.panel_set_pos(panel_id, x, y) -const - MINARGS = 3; -var - PID, WID, X, Y: Integer; - Pan: PPanel; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - PID := luaL_checkinteger(L, 1); - X := luaL_checkinteger(L, 2); - Y := luaL_checkinteger(L, 3); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) then exit; - if not (Pan.PanelType in [PANEL_BACK, PANEL_FORE]) then - begin - g_Console_Add('SCRIPT: panel_set_pos(): can only set pos for BACK and FORE right now'); - exit; - end; - Pan^.X := X; - Pan^.Y := Y; - if g_Game_IsNet then - MH_SEND_PanelState(Pan^.PanelType, WID); -end; - -function SP_Lua_DoorGetState(L: PScriptContext): Integer; cdecl; -// game.door_get_open(panel_id) -const - MINARGS = 1; -var - PID, WID: Integer; - Pan: PPanel; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - PID := luaL_checkinteger(L, 1); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) or (not Pan^.Door) then - lua_pushnil(L) - else - lua_pushboolean(L, Pan^.Enabled); -end; - -function SP_Lua_LiftGetDir(L: PScriptContext): Integer; cdecl; -// game.lift_get_dir(panel_id) -const - MINARGS = 1; -var - PID, WID: Integer; - Pan: PPanel; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - PID := luaL_checkinteger(L, 1); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) or ((Pan^.LiftType = 0) and (Pan^.PanelType <> PANEL_LIFTUP)) then - lua_pushnil(L) - else - lua_pushinteger(L, Pan^.LiftType); -end; - -function SP_Lua_DoorOpen(L: PScriptContext): Integer; cdecl; -// game.door_open(panel_id[, silent=false, d2d_like=false]) -const - MINARGS = 1; -var - D2D, NoSound: Boolean; - PID, WID: Integer; - Pan: PPanel; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - PID := luaL_checkinteger(L, 1); - NoSound := lua_toboolean(L, 2); - D2D := lua_toboolean(L, 3); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) or (not Pan^.Door) then exit; - tr_OpenDoor(WID, NoSound, D2D); -end; - -function SP_Lua_DoorClose(L: PScriptContext): Integer; cdecl; -// game.door_close(panel_id[, silent=false, d2d_like=false]) -const - MINARGS = 1; -var - D2D, NoSound: Boolean; - PID, WID: Integer; - Pan: PPanel; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - PID := luaL_checkinteger(L, 1); - NoSound := lua_toboolean(L, 2); - D2D := lua_toboolean(L, 3); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) or (not Pan^.Door) then exit; - tr_CloseDoor(WID, NoSound, D2D); -end; - -function SP_Lua_DoorToggle(L: PScriptContext): Integer; cdecl; -// game.door_toggle(panel_id[, silent=false, d2d_like=false]) -const - MINARGS = 1; -var - D2D, NoSound: Boolean; - PID, WID: Integer; - Pan: PPanel; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - PID := luaL_checkinteger(L, 1); - NoSound := lua_toboolean(L, 2); - D2D := lua_toboolean(L, 3); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) or (not Pan^.Door) then exit; - if gWalls[WID].Enabled then - tr_OpenDoor(WID, NoSound, D2D) - else - tr_CloseDoor(WID, NoSound, D2D); -end; - -function SP_Lua_DoorCloseTrap(L: PScriptContext): Integer; cdecl; -// game.door_close_trap(panel_id[, silent=false, d2d_like=false]) -const - MINARGS = 1; -var - D2D, NoSound: Boolean; - PID, WID: Integer; - Pan: PPanel; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - PID := luaL_checkinteger(L, 1); - NoSound := lua_toboolean(L, 2); - D2D := lua_toboolean(L, 3); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) or (not Pan^.Door) then exit; - tr_CloseTrap(WID, NoSound, D2D); -end; - -function SP_Lua_LiftSetDir(L: PScriptContext): Integer; cdecl; -// game.lift_set_dir(panel_id, dir[, silent=false, d2d_like=false]) -const - MINARGS = 2; -var - D2D, NoSound: Boolean; - PID, WID, Dir: Integer; - Pan: PPanel; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - PID := luaL_checkinteger(L, 1); - Dir := luaL_checkinteger(L, 2); - NoSound := lua_toboolean(L, 3); - D2D := lua_toboolean(L, 4); - - WID := -1; - Pan := g_Map_PanelForPID(PID, WID); - if (Pan = nil) or ((Pan^.LiftType = 0) and (Pan^.PanelType <> PANEL_LIFTUP)) then - exit; - tr_SetLift(WID, Dir, NoSound, D2D); -end; - -// spawners // - -function SP_Lua_SpawnShot(L: PScriptContext): Integer; cdecl; -// game.spawn_shot(type, x, y, vel_x, vel_y[, silent=false, target_id=0(noone)]) -const - MINARGS = 5; -var - wx, wy, dx, dy, ShotType, ShotTarget: Integer; - Silent: Boolean; - ShotTargetW: Word; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - ShotType := luaL_checkinteger(L, 1); - wx := luaL_checkinteger(L, 2); - wy := luaL_checkinteger(L, 3); - dx := luaL_checkinteger(L, 4); - dy := luaL_checkinteger(L, 5); - - Silent := lua_toboolean(L, 6); - ShotTarget := lua_tointeger(L, 7); - ShotTargetW := 0; - if (ShotTarget > 0) and (ShotTarget < $FFFF) then - ShotTargetW := ShotTarget; - - lua_pushinteger(L, tr_SpawnShot(ShotType, wx, wy, dx, dy, not Silent, ShotTargetW)); -end; - -function SP_Lua_SpawnEffect(L: PScriptContext): Integer; cdecl; -// game.spawn_effect(type, subtype, x, y, vel_x, vel_y[, silent=false, r=0, g=0, b=0]) -const - MINARGS = 6; -var - X, Y, VX, VY: Integer; - EType, ESubType: Integer; - ER, EG, EB: Integer; - Silent: Boolean; -begin - Result := 0; - if not CheckArgs(L, MINARGS) then exit; - - EType := luaL_checkinteger(L, 1); - ESubType := luaL_checkinteger(L, 2); - X := luaL_checkinteger(L, 3); - Y := luaL_checkinteger(L, 4); - VX := luaL_checkinteger(L, 5); - VY := luaL_checkinteger(L, 6); - - Silent := lua_toboolean(L, 7); - ER := lua_tointeger(L, 8); - EG := lua_tointeger(L, 8); - EB := lua_tointeger(L, 8); - - tr_MakeEffect(X, Y, VX, VY, EType, ESubType, ER, EG, EB, Silent, True); -end; - -function SP_Lua_SpawnMonster(L: PScriptContext): Integer; cdecl; -// game.spawn_monster(type, x, y[, dir=left, awake=false, health=default, aitype=normal]) -const - MINARGS = 3; -var - X, Y: Integer; - Dir: TDirection; - MType, MBType, MHP: Integer; - MAwake: Boolean; - MID, i: Integer; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - MType := luaL_checkinteger(L, 1); - X := luaL_checkinteger(L, 2); - Y := luaL_checkinteger(L, 3); - - Dir := TDirection(lua_tointeger(L, 4) mod 2); - MAwake := lua_toboolean(L, 5); - MHP := lua_tointeger(L, 6); - MBType := lua_tointeger(L, 7); - - MID := -1; - - if MType in [MONSTER_DEMON..MONSTER_MAN] then - begin - i := g_Monsters_Create(MType, X, Y, Dir, True); - if i < 0 then exit; - if MHP > 0 then - gMonsters[i].SetHealth(MHP); - gMonsters[i].MonsterBehaviour := MBType; - gMonsters[i].FNoRespawn := True; - if g_Game_IsNet then - MH_SEND_MonsterSpawn(gMonsters[i].UID); - if MAwake then - gMonsters[i].WakeUp(); - if MType <> MONSTER_BARREL then Inc(gTotalMonsters); - if g_Game_IsNet then - begin - SetLength(gMonstersSpawned, Length(gMonstersSpawned)+1); - gMonstersSpawned[High(gMonstersSpawned)] := gMonsters[i].UID; - MH_SEND_GameStats(); - MH_SEND_CoopStats(); - end; - MID := gMonsters[i].UID; - end; - - lua_pushinteger(L, MID); -end; - -function SP_Lua_SpawnItem(L: PScriptContext): Integer; cdecl; -// game.spawn_item(type, x, y[, falls=false]) -const - MINARGS = 3; -var - X, Y: Integer; - IType: Integer; - IFalls: Boolean; - i: Integer; -begin - Result := 1; - if not CheckArgs(L, MINARGS) then - begin - Result := 0; - exit; - end; - - IType := luaL_checkinteger(L, 1); - X := luaL_checkinteger(L, 2); - Y := luaL_checkinteger(L, 3); - - IFalls := lua_toboolean(L, 4); - - i := -1; - if IType in [ITEM_MEDKIT_SMALL..ITEM_MAX] then - begin - i := g_Items_Create(X, Y, IType, IFalls, False, True); - if g_Game_IsNet then - MH_SEND_ItemSpawn(True, i); - end; - - lua_pushinteger(L, i); -end; - -end. diff --git a/src/game/g_scripts.pas b/src/game/g_scripts.pas deleted file mode 100644 index d1113c9..0000000 --- a/src/game/g_scripts.pas +++ /dev/null @@ -1,296 +0,0 @@ -(* Copyright (C) DooM 2D:Forever Developers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - *) -{$MODE DELPHI} -unit g_scripts; - -interface - -uses - lua, lualib, lauxlib; - -const - // reset levels - RESET_SRV_BIT = 4; - RESET_WAD_BIT = 2; - RESET_MAP_BIT = 1; - RESET_SRV = RESET_SRV_BIT or RESET_WAD_BIT or RESET_MAP_BIT; - RESET_WAD = RESET_WAD_BIT or RESET_MAP_BIT; - RESET_MAP = RESET_MAP_BIT; - RESET_ALL = 255; - -type - PScriptContext = Plua_State; - PScriptProc = lua_CFunction; - -var - gScriptCtx: PScriptContext = nil; - gScriptInit: Boolean = False; - -function g_Scripts_Init(): Boolean; -procedure g_Scripts_Reset(What: Byte); -function g_Scripts_ProcExec(PName: string; const Args: array of const; Namespace: string = ''): Integer; -function g_Scripts_ProcExists(PName: string): Boolean; -function g_Scripts_ProcInstall(PName: string; PPtr: PScriptProc): Boolean; -function g_Scripts_Load(Text: string): Boolean; -procedure g_Scripts_Free(); - -implementation - -uses - SysUtils, g_console, g_scriptprocs; - -type - TLuaReg = record - name: PAnsiChar; - func: lua_CFunction; - end; - -const - LUA_LIBS: array [0..6] of TLuaReg = ( - (name: ''; func: luaopen_base), - (name: LUA_LOADLIBNAME; func: luaopen_package), - (name: LUA_TABLIBNAME; func: luaopen_table), - (name: LUA_STRLIBNAME; func: luaopen_string), - (name: LUA_MATHLIBNAME; func: luaopen_math), - (name: LUA_OSLIBNAME; func: luaopen_os), // TODO: something to restrict these two - (name: LUA_IOLIBNAME; func: luaopen_io) - ); - -function LuaInstallGameFuncs(): Boolean; -begin - Result := False; - - if not g_Scripts_ProcInstall('conprint', SP_Lua_ConPrint) then Exit; - if not g_Scripts_ProcInstall('message', SP_Lua_Message) then Exit; - if not g_Scripts_ProcInstall('sound', SP_Lua_PlaySound) then Exit; - if not g_Scripts_ProcInstall('get_gamemode', SP_Lua_GetGameMode) then Exit; - if not g_Scripts_ProcInstall('get_gametype', SP_Lua_GetGameType) then Exit; - if not g_Scripts_ProcInstall('get_time', SP_Lua_GetTime) then Exit; - - if not g_Scripts_ProcInstall('player_get_keys', SP_Lua_PlayerGetKeys) then Exit; - if not g_Scripts_ProcInstall('player_get_armor', SP_Lua_PlayerGetArmor) then Exit; - if not g_Scripts_ProcInstall('player_get_score', SP_Lua_PlayerGetScore) then Exit; - if not g_Scripts_ProcInstall('player_get_name', SP_Lua_PlayerGetName) then Exit; - if not g_Scripts_ProcInstall('player_get_team', SP_Lua_PlayerGetTeam) then Exit; - - if not g_Scripts_ProcInstall('uid_get_health', SP_Lua_ActorGetHealth) then Exit; - if not g_Scripts_ProcInstall('uid_get_pos', SP_Lua_ActorGetPos) then Exit; - if not g_Scripts_ProcInstall('uid_get_state', SP_Lua_ActorGetState) then Exit; - if not g_Scripts_ProcInstall('uid_get_type', SP_Lua_ActorGetType) then Exit; - if not g_Scripts_ProcInstall('uid_nearest', SP_Lua_ActorNearest) then Exit; - if not g_Scripts_ProcInstall('uid_farthest', SP_Lua_ActorFarthest) then Exit; - if not g_Scripts_ProcInstall('uid_damage', SP_Lua_ActorDamage) then Exit; - if not g_Scripts_ProcInstall('uid_push', SP_Lua_ActorPush) then Exit; - if not g_Scripts_ProcInstall('uid_teleport', SP_Lua_ActorTeleport) then Exit; - - if not g_Scripts_ProcInstall('trigger_get_enabled', SP_Lua_TriggerGetEnabled) then Exit; - if not g_Scripts_ProcInstall('trigger_set_enabled', SP_Lua_TriggerSetEnabled) then Exit; - if not g_Scripts_ProcInstall('trigger_activate', SP_Lua_TriggerActivate) then Exit; - if not g_Scripts_ProcInstall('trigger_get_pos', SP_Lua_TriggerGetPos) then Exit; - if not g_Scripts_ProcInstall('trigger_set_pos', SP_Lua_TriggerSetPos) then Exit; - - if not g_Scripts_ProcInstall('panel_get_type', SP_Lua_PanelGetType) then Exit; - if not g_Scripts_ProcInstall('panel_get_pos', SP_Lua_PanelGetPos) then Exit; - if not g_Scripts_ProcInstall('panel_get_size', SP_Lua_PanelGetSize) then Exit; - if not g_Scripts_ProcInstall('panel_set_pos', SP_Lua_PanelSetPos) then Exit; - if not g_Scripts_ProcInstall('panel_switch_texture', SP_Lua_PanelSwitchTexture) then Exit; - - if not g_Scripts_ProcInstall('door_get_open', SP_Lua_DoorGetState) then Exit; - if not g_Scripts_ProcInstall('door_close', SP_Lua_DoorClose) then Exit; - if not g_Scripts_ProcInstall('door_close_trap', SP_Lua_DoorCloseTrap) then Exit; - if not g_Scripts_ProcInstall('door_open', SP_Lua_DoorOpen) then Exit; - if not g_Scripts_ProcInstall('door_toggle', SP_Lua_DoorToggle) then Exit; - if not g_Scripts_ProcInstall('lift_get_dir', SP_Lua_LiftGetDir) then Exit; - if not g_Scripts_ProcInstall('lift_set_dir', SP_Lua_LiftSetDir) then Exit; - - if not g_Scripts_ProcInstall('spawn_item', SP_Lua_SpawnItem) then Exit; - if not g_Scripts_ProcInstall('spawn_shot', SP_Lua_SpawnShot) then Exit; - if not g_Scripts_ProcInstall('spawn_effect', SP_Lua_SpawnEffect) then Exit; - if not g_Scripts_ProcInstall('spawn_monster', SP_Lua_SpawnMonster) then Exit; - - Result := True; -end; - -function g_Scripts_Init(): Boolean; -var - i: Integer; -begin - Result := False; - if gScriptInit then Exit; - - gScriptCtx := luaL_newstate(); - if gScriptCtx = nil then Exit; - - // don't open all the libs - for i := 0 to High(LUA_LIBS) do - begin - lua_pushcfunction(gScriptCtx, LUA_LIBS[i].func); - lua_pushstring(gScriptCtx, LUA_LIBS[i].name); - lua_call(gScriptCtx, 1, 0); - end; - - // create a table for game-related functions - lua_newtable(gScriptCtx); - lua_setglobal(gScriptCtx, 'game'); - - // create game-related tables - g_Scripts_Reset(RESET_ALL); - - gScriptInit := True; - // try to install game-related shit - if not LuaInstallGameFuncs() then - begin - g_Console_Add('SCRIPT: Could not init game callbacks'); - lua_close(gScriptCtx); - gScriptCtx := nil; - gScriptInit := False; - Exit; - end; - - Result := True; -end; - -// TODO: maybe actually put some fields into these? -procedure g_Scripts_Reset(What: Byte); -begin - if not gScriptInit then Exit; - if LongBool(What and RESET_SRV_BIT) then - begin - lua_newtable(gScriptCtx); - lua_setglobal(gScriptCtx, 'srv'); - end; - if LongBool(What and RESET_WAD_BIT) then - begin - lua_newtable(gScriptCtx); - lua_setglobal(gScriptCtx, 'wad'); - end; - if LongBool(What and RESET_MAP_BIT) then - begin - lua_newtable(gScriptCtx); - lua_setglobal(gScriptCtx, 'map'); - - // disable io and os modules on any kind of reset - lua_pushnil(gScriptCtx); - lua_pushnil(gScriptCtx); - lua_setglobal(gScriptCtx, 'os'); - lua_setglobal(gScriptCtx, 'io'); - end; -end; - -function g_Scripts_ProcInstall(PName: string; PPtr: PScriptProc): Boolean; -begin - Result := False; - if not gScriptInit then Exit; - - if g_Scripts_ProcExists(PName) then - begin - g_Console_Add('SCRIPT: ProcInstall(' + PName + '): function already exists'); - Exit; - end; - - lua_getglobal(gScriptCtx, 'game'); - lua_pushstring(gScriptCtx, PName); - lua_pushcfunction(gScriptCtx, PPtr); - lua_settable(gScriptCtx, -3); - lua_setglobal(gScriptCtx, 'game'); - - Result := True; -end; - -function g_Scripts_ProcExists(PName: string): Boolean; -begin - Result := False; - if not gScriptInit then Exit; - - lua_getglobal(gScriptCtx, 'game'); - lua_pushstring(gScriptCtx, PName); - lua_gettable(gScriptCtx, -2); - - if lua_isfunction(gScriptCtx, -1) then - Result := True; -end; - -function g_Scripts_ProcExec(PName: string; const Args: array of const; Namespace: string = ''): Integer; -var - i: Integer; -begin - Result := -255; - if not gScriptInit then Exit; - - if Namespace = '' then - lua_getglobal(gScriptCtx, PChar(PName)) - else - begin - lua_getglobal(gScriptCtx, PChar(Namespace)); - lua_pushstring(gScriptCtx, PName); - lua_gettable(gScriptCtx, -2); - end; - - if not lua_isfunction(gScriptCtx, -1) then - begin - g_Console_Add('SCRIPT: ProcExec(' + Namespace + '.' + PName + ') error: no such function'); - Exit; - end; - - for i := 0 to High(Args) do - with Args[i] do - begin - case VType of - vtInteger: lua_pushinteger(gScriptCtx, vInteger); - vtBoolean: lua_pushboolean(gScriptCtx, vBoolean); - vtString: lua_pushstring(gScriptCtx, vString^); - vtAnsiString: lua_pushstring(gScriptCtx, PAnsiString(vAnsiString)^); - vtExtended: lua_pushnumber(gScriptCtx, vExtended^); - end; - end; - - if lua_pcall(gScriptCtx, Length(Args), 1, 0) <> 0 then - begin - g_Console_Add('SCRIPT: ProcExec(' + Namespace + '.' + PName + ') error: ' + lua_tostring(gScriptCtx, -1)); - Exit; - end; - - Result := 0; - if lua_isnumber(gScriptCtx, -1) then - begin - Result := lua_tointeger(gScriptCtx, -1); - lua_pop(gScriptCtx, 1); - end; -end; - -function g_Scripts_Load(Text: string): Boolean; -begin - Result := False; - if not gScriptInit then Exit; - - if lua_dostring(gScriptCtx, PChar(Text)) <> 0 then - begin - g_Console_Add('SCRIPT: Load() error: ' + lua_tostring(gScriptCtx, -1)); - Exit; - end; - - Result := True; -end; - -procedure g_Scripts_Free(); -begin - if not gScriptInit then Exit; - lua_close(gScriptCtx); - gScriptInit := False; - gScriptCtx := nil; -end; - -end. diff --git a/src/game/g_triggers.pas b/src/game/g_triggers.pas index 9ca5756..8c1c1b8 100644 --- a/src/game/g_triggers.pas +++ b/src/game/g_triggers.pas @@ -101,7 +101,7 @@ uses g_player, g_map, Math, g_gfx, g_game, g_textures, g_console, g_monsters, g_items, g_phys, g_weapons, wadreader, g_main, SysUtils, e_log, g_language, - g_options, g_net, g_netmsg, g_scripts; + g_options, g_net, g_netmsg; const TRIGGER_SIGNATURE = $52475254; // 'TRGR' @@ -2018,13 +2018,6 @@ begin end; TimeOut := Data.FXWait; end; - - TRIGGER_SCRIPT: - begin - g_Scripts_ProcExec(Data.SCRProc, [ID, ActivateUID, actType, Data.SCRArg], 'map'); - TimeOut := 0; - Result := True; - end; end; end; diff --git a/src/lib/lua/lauxlib.pas b/src/lib/lua/lauxlib.pas deleted file mode 100644 index 650bd72..0000000 --- a/src/lib/lua/lauxlib.pas +++ /dev/null @@ -1,380 +0,0 @@ -(****************************************************************************** - * * - * File: lauxlib.pas * - * Authors: TeCGraf (C headers + actual Lua libraries) * - * Lavergne Thomas (original translation to Pascal) * - * Bram Kuijvenhoven (update to Lua 5.1.1 for FreePascal) * - * Description: Lua auxiliary library * - * * - ******************************************************************************) - -(* -** $Id: lauxlib.h,v 1.59 2003/03/18 12:25:32 roberto Exp $ -** Auxiliary functions for building Lua libraries -** See Copyright Notice in lua.h -*) -(* -** Translated to pascal by Lavergne Thomas -** Notes : -** - Pointers type was prefixed with 'P' -** Bug reports : -** - thomas.lavergne@laposte.net -** In french or in english -*) - -{$IFDEF FPC}{$MODE OBJFPC}{$H+}{$ENDIF} - -unit lauxlib; - -interface - -uses - Lua; - -// functions added for Pascal -procedure lua_pushstring(L: Plua_State; const s: string); - -// compatibilty macros -function luaL_getn(L: Plua_State; n: Integer): Integer; // calls lua_objlen -procedure luaL_setn(L: Plua_State; t, n: Integer); // does nothing! - -type - luaL_reg = record - name: PChar; - func: lua_CFunction; - end; - PluaL_reg = ^luaL_reg; - -procedure luaL_openlib(L: Plua_State; const libname: PChar; const lr: PluaL_reg; nup: Integer); cdecl; -procedure luaL_register(L: Plua_State; const libname: PChar; const lr: PluaL_reg); cdecl; -function luaL_getmetafield(L: Plua_State; obj: Integer; const e: PChar): Integer; cdecl; -function luaL_callmeta(L: Plua_State; obj: Integer; const e: PChar): Integer; cdecl; -function luaL_typerror(L: Plua_State; narg: Integer; const tname: PChar): Integer; cdecl; -function luaL_argerror(L: Plua_State; numarg: Integer; const extramsg: PChar): Integer; cdecl; -function luaL_checklstring(L: Plua_State; numArg: Integer; l_: Psize_t): PChar; cdecl; -function luaL_optlstring(L: Plua_State; numArg: Integer; const def: PChar; l_: Psize_t): PChar; cdecl; -function luaL_checknumber(L: Plua_State; numArg: Integer): lua_Number; cdecl; -function luaL_optnumber(L: Plua_State; nArg: Integer; def: lua_Number): lua_Number; cdecl; -function luaL_checkinteger(L: Plua_State; numArg: Integer): lua_Integer; cdecl; -function luaL_optinteger(L: Plua_State; nArg: Integer; def: lua_Integer): lua_Integer; cdecl; - -procedure luaL_checkstack(L: Plua_State; sz: Integer; const msg: PChar); cdecl; -procedure luaL_checktype(L: Plua_State; narg, t: Integer); cdecl; -procedure luaL_checkany(L: Plua_State; narg: Integer); cdecl; - -function luaL_newmetatable(L: Plua_State; const tname: PChar): Integer; cdecl; -function luaL_checkudata(L: Plua_State; ud: Integer; const tname: PChar): Pointer; cdecl; - -procedure luaL_where(L: Plua_State; lvl: Integer); cdecl; -function luaL_error(L: Plua_State; const fmt: PChar; args: array of const): Integer; cdecl; external LUA_LIB_NAME; // note: C's ... to array of const conversion is not portable to Delphi - -function luaL_checkoption(L: Plua_State; narg: Integer; def: PChar; lst: PPChar): Integer; cdecl; - -function luaL_ref(L: Plua_State; t: Integer): Integer; cdecl; -procedure luaL_unref(L: Plua_State; t, ref: Integer); cdecl; - -function luaL_loadfile(L: Plua_State; const filename: PChar): Integer; cdecl; -function luaL_loadbuffer(L: Plua_State; const buff: PChar; size: size_t; const name: PChar): Integer; cdecl; -function luaL_loadstring(L: Plua_State; const s: PChar): Integer; cdecl; - -function luaL_newstate: Plua_State; cdecl; -function lua_open: Plua_State; // compatibility; moved from unit lua to lauxlib because it needs luaL_newstate - -function luaL_gsub(L: Plua_State; const s, p, r: PChar): PChar; cdecl; -function luaL_findtable(L: Plua_State; idx: Integer; const fname: PChar; szhint: Integer): PChar; cdecl; - -(* -** =============================================================== -** some useful macros -** =============================================================== -*) - -procedure luaL_argcheck(L: Plua_State; cond: Boolean; numarg: Integer; extramsg: PChar); -function luaL_checkstring(L: Plua_State; n: Integer): PChar; -function luaL_optstring(L: Plua_State; n: Integer; d: PChar): PChar; -function luaL_checkint(L: Plua_State; n: Integer): Integer; -function luaL_checklong(L: Plua_State; n: Integer): LongInt; -function luaL_optint(L: Plua_State; n: Integer; d: Double): Integer; -function luaL_optlong(L: Plua_State; n: Integer; d: Double): LongInt; - -function luaL_typename(L: Plua_State; i: Integer): PChar; - -function lua_dofile(L: Plua_State; const filename: PChar): Integer; -function lua_dostring(L: Plua_State; const str: PChar): Integer; - -procedure lua_Lgetmetatable(L: Plua_State; tname: PChar); - -// not translated: -// #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) - - -(* -** ======================================================= -** Generic Buffer manipulation -** ======================================================= -*) - -const - // note: this is just arbitrary, as it related to the BUFSIZ defined in stdio.h ... - LUAL_BUFFERSIZE = 4096; - -type - luaL_Buffer = record - p: PChar; (* current position in buffer *) - lvl: Integer; (* number of strings in the stack (level) *) - L: Plua_State; - buffer: array [0..LUAL_BUFFERSIZE - 1] of Char; // warning: see note above about LUAL_BUFFERSIZE - end; - PluaL_Buffer = ^luaL_Buffer; - -procedure luaL_addchar(B: PluaL_Buffer; c: Char); // warning: see note above about LUAL_BUFFERSIZE - -(* compatibility only (alias for luaL_addchar) *) -procedure luaL_putchar(B: PluaL_Buffer; c: Char); // warning: see note above about LUAL_BUFFERSIZE - -procedure luaL_addsize(B: PluaL_Buffer; n: Integer); - -procedure luaL_buffinit(L: Plua_State; B: PluaL_Buffer); cdecl; -function luaL_prepbuffer(B: PluaL_Buffer): PChar; cdecl; -procedure luaL_addlstring(B: PluaL_Buffer; const s: PChar; l: size_t); cdecl; -procedure luaL_addstring(B: PluaL_Buffer; const s: PChar); cdecl; -procedure luaL_addvalue(B: PluaL_Buffer); cdecl; -procedure luaL_pushresult(B: PluaL_Buffer); cdecl; - - -(* compatibility with ref system *) - -(* pre-defined references *) -const - LUA_NOREF = -2; - LUA_REFNIL = -1; - -procedure lua_unref(L: Plua_State; ref: Integer); -procedure lua_getref(L: Plua_State; ref: Integer); - -(* -** Compatibility macros and functions -*) - -function luaL_check_lstr(L: Plua_State; numArg: Integer; len: Psize_t): PChar; -function luaL_opt_lstr(L: Plua_State; numArg: Integer; const def: PChar; len: Psize_t): PChar; -function luaL_check_number(L: Plua_State; numArg: Integer): lua_Number; -function luaL_opt_number(L: Plua_State; nArg: Integer; def: lua_Number): lua_Number; -procedure luaL_arg_check(L: Plua_State; cond: Boolean; numarg: Integer; extramsg: PChar); -function luaL_check_string(L: Plua_State; n: Integer): PChar; -function luaL_opt_string(L: Plua_State; n: Integer; d: PChar): PChar; -function luaL_check_int(L: Plua_State; n: Integer): Integer; -function luaL_check_long(L: Plua_State; n: Integer): LongInt; -function luaL_opt_int(L: Plua_State; n: Integer; d: Double): Integer; -function luaL_opt_long(L: Plua_State; n: Integer; d: Double): LongInt; - -implementation - -procedure lua_pushstring(L: Plua_State; const s: string); -begin - lua_pushlstring(L, PChar(s), Length(s)); -end; - -function luaL_getn(L: Plua_State; n: Integer): Integer; -begin - Result := lua_objlen(L, n); -end; - -procedure luaL_setn(L: Plua_State; t, n: Integer); -begin - // does nothing as this operation is deprecated -end; - -procedure luaL_openlib(L: Plua_State; const libname: PChar; const lr: PluaL_reg; nup: Integer); cdecl; external LUA_LIB_NAME; -procedure luaL_register(L: Plua_State; const libname: PChar; const lr: PluaL_reg); cdecl; external LUA_LIB_NAME; -function luaL_getmetafield(L: Plua_State; obj: Integer; const e: PChar): Integer; cdecl; external LUA_LIB_NAME; -function luaL_callmeta(L: Plua_State; obj: Integer; const e: PChar): Integer; cdecl; external LUA_LIB_NAME; -function luaL_typerror(L: Plua_State; narg: Integer; const tname: PChar): Integer; cdecl; external LUA_LIB_NAME; -function luaL_argerror(L: Plua_State; numarg: Integer; const extramsg: PChar): Integer; cdecl; external LUA_LIB_NAME; -function luaL_checklstring(L: Plua_State; numArg: Integer; l_: Psize_t): PChar; cdecl; external LUA_LIB_NAME; -function luaL_optlstring(L: Plua_State; numArg: Integer; const def: PChar; l_: Psize_t): PChar; cdecl; external LUA_LIB_NAME; -function luaL_checknumber(L: Plua_State; numArg: Integer): lua_Number; cdecl; external LUA_LIB_NAME; -function luaL_optnumber(L: Plua_State; nArg: Integer; def: lua_Number): lua_Number; cdecl; external LUA_LIB_NAME; -function luaL_checkinteger(L: Plua_State; numArg: Integer): lua_Integer; cdecl; external LUA_LIB_NAME; -function luaL_optinteger(L: Plua_State; nArg: Integer; def: lua_Integer): lua_Integer; cdecl; external LUA_LIB_NAME; - -procedure luaL_checkstack(L: Plua_State; sz: Integer; const msg: PChar); cdecl; external LUA_LIB_NAME; -procedure luaL_checktype(L: Plua_State; narg, t: Integer); cdecl; external LUA_LIB_NAME; -procedure luaL_checkany(L: Plua_State; narg: Integer); cdecl; external LUA_LIB_NAME; - -function luaL_newmetatable(L: Plua_State; const tname: PChar): Integer; cdecl; external LUA_LIB_NAME; -function luaL_checkudata(L: Plua_State; ud: Integer; const tname: PChar): Pointer; cdecl; external LUA_LIB_NAME; - -procedure luaL_where(L: Plua_State; lvl: Integer); cdecl; external LUA_LIB_NAME; -// function luaL_error(L: Plua_State; const fmt: PChar; args: array of const): Integer; cdecl; external LUA_LIB_NAME; - -function luaL_checkoption(L: Plua_State; narg: Integer; def: PChar; lst: PPChar): Integer; cdecl; external LUA_LIB_NAME; - -function luaL_ref(L: Plua_State; t: Integer): Integer; cdecl; external LUA_LIB_NAME; -procedure luaL_unref(L: Plua_State; t, ref: Integer); cdecl; external LUA_LIB_NAME; - -function luaL_loadfile(L: Plua_State; const filename: PChar): Integer; cdecl; external LUA_LIB_NAME; -function luaL_loadbuffer(L: Plua_State; const buff: PChar; size: size_t; const name: PChar): Integer; cdecl; external LUA_LIB_NAME; -function luaL_loadstring(L: Plua_State; const s: PChar): Integer; cdecl; external LUA_LIB_NAME; - -function luaL_newstate: Plua_State; cdecl; external LUA_LIB_NAME; - -function lua_open: Plua_State; -begin - Result := luaL_newstate; -end; - -function luaL_gsub(L: Plua_State; const s, p, r: PChar): PChar; cdecl; external LUA_LIB_NAME; -function luaL_findtable(L: Plua_State; idx: Integer; const fname: PChar; szhint: Integer): PChar; cdecl; external LUA_LIB_NAME; - -function luaL_typename(L: Plua_State; i: Integer): PChar; -begin - Result := lua_typename(L, lua_type(L, i)); -end; - -function lua_dofile(L: Plua_State; const filename: PChar): Integer; -begin - Result := luaL_loadfile(L, filename); - if Result = 0 then - Result := lua_pcall(L, 0, LUA_MULTRET, 0); -end; - -function lua_dostring(L: Plua_State; const str: PChar): Integer; -begin - Result := luaL_loadstring(L, str); - if Result = 0 then - Result := lua_pcall(L, 0, LUA_MULTRET, 0); -end; - -procedure lua_Lgetmetatable(L: Plua_State; tname: PChar); -begin - lua_getfield(L, LUA_REGISTRYINDEX, tname); -end; - -procedure luaL_argcheck(L: Plua_State; cond: Boolean; numarg: Integer; extramsg: PChar); -begin - if not cond then - luaL_argerror(L, numarg, extramsg) -end; - -function luaL_checkstring(L: Plua_State; n: Integer): PChar; -begin - Result := luaL_checklstring(L, n, nil) -end; - -function luaL_optstring(L: Plua_State; n: Integer; d: PChar): PChar; -begin - Result := luaL_optlstring(L, n, d, nil) -end; - -function luaL_checkint(L: Plua_State; n: Integer): Integer; -begin - Result := Integer(Trunc(luaL_checknumber(L, n))) -end; - -function luaL_checklong(L: Plua_State; n: Integer): LongInt; -begin - Result := LongInt(Trunc(luaL_checknumber(L, n))) -end; - -function luaL_optint(L: Plua_State; n: Integer; d: Double): Integer; -begin - Result := Integer(Trunc(luaL_optnumber(L, n, d))) -end; - -function luaL_optlong(L: Plua_State; n: Integer; d: Double): LongInt; -begin - Result := LongInt(Trunc(luaL_optnumber(L, n, d))) -end; - -procedure luaL_addchar(B: PluaL_Buffer; c: Char); -begin - if Cardinal(@(B^.p)) < (Cardinal(@(B^.buffer[0])) + LUAL_BUFFERSIZE) then - luaL_prepbuffer(B); - B^.p[1] := c; - B^.p := B^.p + 1; -end; - -procedure luaL_putchar(B: PluaL_Buffer; c: Char); -begin - luaL_addchar(B, c); -end; - -procedure luaL_addsize(B: PluaL_Buffer; n: Integer); -begin - B^.p := B^.p + n; -end; - -procedure luaL_buffinit(L: Plua_State ; B: PluaL_Buffer); cdecl; external LUA_LIB_NAME; -function luaL_prepbuffer(B: PluaL_Buffer): PChar; cdecl; external LUA_LIB_NAME; -procedure luaL_addlstring(B: PluaL_Buffer; const s: PChar; l: size_t); cdecl; external LUA_LIB_NAME; -procedure luaL_addstring(B: PluaL_Buffer; const s: PChar); cdecl; external LUA_LIB_NAME; -procedure luaL_addvalue(B: PluaL_Buffer); cdecl; external LUA_LIB_NAME; -procedure luaL_pushresult(B: PluaL_Buffer); cdecl; external LUA_LIB_NAME; - -procedure lua_unref(L: Plua_State; ref: Integer); -begin - luaL_unref(L, LUA_REGISTRYINDEX, ref); -end; - -procedure lua_getref(L: Plua_State; ref: Integer); -begin - lua_rawgeti(L, LUA_REGISTRYINDEX, ref); -end; - -function luaL_check_lstr(L: Plua_State; numArg: Integer; len: Psize_t): PChar; -begin - Result := luaL_checklstring(L, numArg, len); -end; - -function luaL_opt_lstr(L: Plua_State; numArg: Integer; const def: PChar; len: Psize_t): PChar; -begin - Result := luaL_optlstring(L, numArg, def, len); -end; - -function luaL_check_number(L: Plua_State; numArg: Integer): lua_Number; -begin - Result := luaL_checknumber(L, numArg); -end; - -function luaL_opt_number(L: Plua_State; nArg: Integer; def: lua_Number): lua_Number; -begin - Result := luaL_optnumber(L, nArg, def); -end; - -procedure luaL_arg_check(L: Plua_State; cond: Boolean; numarg: Integer; extramsg: PChar); -begin - luaL_argcheck(L, cond, numarg, extramsg); -end; - -function luaL_check_string(L: Plua_State; n: Integer): PChar; -begin - Result := luaL_checkstring(L, n); -end; - -function luaL_opt_string(L: Plua_State; n: Integer; d: PChar): PChar; -begin - Result := luaL_optstring(L, n, d); -end; - -function luaL_check_int(L: Plua_State; n: Integer): Integer; -begin - Result := luaL_checkint(L, n); -end; - -function luaL_check_long(L: Plua_State; n: Integer): LongInt; -begin - Result := luaL_checklong(L, n); -end; - -function luaL_opt_int(L: Plua_State; n: Integer; d: Double): Integer; -begin - Result := luaL_optint(L, n, d); -end; - -function luaL_opt_long(L: Plua_State; n: Integer; d: Double): LongInt; -begin - Result := luaL_optlong(L, n, d); -end; - -end. diff --git a/src/lib/lua/lua.pas b/src/lib/lua/lua.pas deleted file mode 100644 index d3a3a69..0000000 --- a/src/lib/lua/lua.pas +++ /dev/null @@ -1,575 +0,0 @@ -(****************************************************************************** - * * - * File: lua.pas * - * Authors: TeCGraf (C headers + actual Lua libraries) * - * Lavergne Thomas (original translation to Pascal) * - * Bram Kuijvenhoven (update to Lua 5.1.1 for FreePascal) * - * Description: Basic Lua library * - * * - ******************************************************************************) - -(* -** $Id: lua.h,v 1.175 2003/03/18 12:31:39 roberto Exp $ -** Lua - An Extensible Extension Language -** TeCGraf: Computer Graphics Technology Group, PUC-Rio, Brazil -** http://www.lua.org mailto:info@lua.org -** See Copyright Notice at the end of this file -*) -(* -** Updated to Lua 5.1.1 by Bram Kuijvenhoven (bram at kuijvenhoven dot net), -** Hexis BV (http://www.hexis.nl), the Netherlands -** Notes: -** - Only tested with FPC (FreePascal Compiler) -** - Using LuaBinaries styled DLL/SO names, which include version names -** - LUA_YIELD was suffixed by '_' for avoiding name collision -*) -(* -** Translated to pascal by Lavergne Thomas -** Notes : -** - Pointers type was prefixed with 'P' -** - lua_upvalueindex constant was transformed to function -** - Some compatibility function was isolated because with it you must have -** lualib. -** - LUA_VERSION was suffixed by '_' for avoiding name collision. -** Bug reports : -** - thomas.lavergne@laposte.net -** In french or in english -*) - -{$IFDEF FPC}{$MODE OBJFPC}{$H+}{$ENDIF} - -unit lua; - -interface - -const -{$IFDEF UNIX} - LUA_NAME = 'libluajit-5.1.so'; - LUA_LIB_NAME = 'libluajit-5.1.so'; -{$ELSE} - LUA_NAME = 'lua51.dll'; - LUA_LIB_NAME = 'lua51.dll'; -{$ENDIF} - -type - size_t = Cardinal; - Psize_t = ^size_t; - -const - LUA_VERSION = 'Lua 5.1'; - LUA_RELEASE = 'Lua 5.1.1'; - LUA_VERSION_NUM = 501; - LUA_COPYRIGHT = 'Copyright (C) 1994-2006 Lua.org, PUC-Rio'; - LUA_AUTHORS = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes'; - -(* option for multiple returns in `lua_pcall' and `lua_call' *) - LUA_MULTRET = -1; - -(* -** pseudo-indices -*) - LUA_REGISTRYINDEX = -10000; - LUA_ENVIRONINDEX = -10001; - LUA_GLOBALSINDEX = -10002; - -function lua_upvalueindex(I: Integer): Integer; - -const -(* thread status; 0 is OK *) - LUA_YIELD_ = 1; - LUA_ERRRUN = 2; - LUA_ERRSYNTAX = 3; - LUA_ERRMEM = 4; - LUA_ERRERR = 5; - -type - Plua_State = Pointer; - - lua_CFunction = function(L: Plua_State): Integer; cdecl; - -(* -** functions that read/write blocks when loading/dumping Lua chunks -*) -type - lua_Reader = function(L: Plua_State; ud: Pointer; sz: Psize_t): PChar; cdecl; - lua_Writer = function(L: Plua_State; const p: Pointer; sz: size_t; ud: Pointer): Integer; cdecl; - -(* -** prototype for memory-allocation functions -*) - lua_Alloc = function(ud, ptr: Pointer; osize, nsize: size_t): Pointer; cdecl; - -(* -** basic types -*) -const - LUA_TNONE = -1; - - LUA_TNIL = 0; - LUA_TBOOLEAN = 1; - LUA_TLIGHTUSERDATA = 2; - LUA_TNUMBER = 3; - LUA_TSTRING = 4; - LUA_TTABLE = 5; - LUA_TFUNCTION = 6; - LUA_TUSERDATA = 7; - LUA_TTHREAD = 8; - -(* minimum Lua stack available to a C function *) - LUA_MINSTACK = 20; - -type -(* Type of Numbers in Lua *) - lua_Number = Double; - lua_Integer = PtrInt; - -(* -** state manipulation -*) -function lua_newstate(f: lua_Alloc; ud: Pointer): Plua_state; cdecl; -procedure lua_close(L: Plua_State); cdecl; -function lua_newthread(L: Plua_State): Plua_State; cdecl; - -function lua_atpanic(L: Plua_State; panicf: lua_CFunction): lua_CFunction; cdecl; - -(* -** basic stack manipulation -*) -function lua_gettop(L: Plua_State): Integer; cdecl; -procedure lua_settop(L: Plua_State; idx: Integer); cdecl; -procedure lua_pushvalue(L: Plua_State; Idx: Integer); cdecl; -procedure lua_remove(L: Plua_State; idx: Integer); cdecl; -procedure lua_insert(L: Plua_State; idx: Integer); cdecl; -procedure lua_replace(L: Plua_State; idx: Integer); cdecl; -function lua_checkstack(L: Plua_State; sz: Integer): LongBool; cdecl; - -procedure lua_xmove(from, to_: Plua_State; n: Integer); cdecl; - -(* -** access functions (stack -> C) -*) -function lua_isnumber(L: Plua_State; idx: Integer): LongBool; cdecl; -function lua_isstring(L: Plua_State; idx: Integer): LongBool; cdecl; -function lua_iscfunction(L: Plua_State; idx: Integer): LongBool; cdecl; -function lua_isuserdata(L: Plua_State; idx: Integer): LongBool; cdecl; -function lua_type(L: Plua_State; idx: Integer): Integer; cdecl; -function lua_typename(L: Plua_State; tp: Integer): PChar; cdecl; - -function lua_equal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; -function lua_rawequal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; -function lua_lessthan(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; - -function lua_tonumber(L: Plua_State; idx: Integer): lua_Number; cdecl; -function lua_tointeger(L: Plua_State; idx: Integer): lua_Integer; cdecl; -function lua_toboolean(L: Plua_State; idx: Integer): LongBool; cdecl; -function lua_tolstring(L: Plua_State; idx: Integer; len: Psize_t): PChar; cdecl; -function lua_objlen(L: Plua_State; idx: Integer): size_t; cdecl; -function lua_tocfunction(L: Plua_State; idx: Integer): lua_CFunction; cdecl; -function lua_touserdata(L: Plua_State; idx: Integer): Pointer; cdecl; -function lua_tothread(L: Plua_State; idx: Integer): Plua_State; cdecl; -function lua_topointer(L: Plua_State; idx: Integer): Pointer; cdecl; - -(* -** push functions (C -> stack) -*) -procedure lua_pushnil(L: Plua_State); cdecl; -procedure lua_pushnumber(L: Plua_State; n: lua_Number); cdecl; -procedure lua_pushinteger(L: Plua_State; n: lua_Integer); cdecl; -procedure lua_pushlstring(L: Plua_State; const s: PChar; l_: size_t); cdecl; -procedure lua_pushstring(L: Plua_State; const s: PChar); cdecl; -function lua_pushvfstring(L: Plua_State; const fmt: PChar; argp: Pointer): PChar; cdecl; -function lua_pushfstring(L: Plua_State; const fmt: PChar): PChar; cdecl; varargs; -procedure lua_pushcclosure(L: Plua_State; fn: lua_CFunction; n: Integer); cdecl; -procedure lua_pushboolean(L: Plua_State; b: LongBool); cdecl; -procedure lua_pushlightuserdata(L: Plua_State; p: Pointer); cdecl; -procedure lua_pushthread(L: Plua_State); cdecl; - -(* -** get functions (Lua -> stack) -*) -procedure lua_gettable(L: Plua_State; idx: Integer); cdecl; -procedure lua_getfield(L: Plua_state; idx: Integer; k: PChar); cdecl; -procedure lua_rawget(L: Plua_State; idx: Integer); cdecl; -procedure lua_rawgeti(L: Plua_State; idx, n: Integer); cdecl; -procedure lua_createtable(L: Plua_State; narr, nrec: Integer); cdecl; -function lua_newuserdata(L: Plua_State; sz: size_t): Pointer; cdecl; -function lua_getmetatable(L: Plua_State; objindex: Integer): Integer; cdecl; -procedure lua_getfenv(L: Plua_State; idx: Integer); cdecl; - -(* -** set functions (stack -> Lua) -*) -procedure lua_settable(L: Plua_State; idx: Integer); cdecl; -procedure lua_setfield(L: Plua_State; idx: Integer; k: PChar); cdecl; -procedure lua_rawset(L: Plua_State; idx: Integer); cdecl; -procedure lua_rawseti(L: Plua_State; idx, n: Integer); cdecl; -function lua_setmetatable(L: Plua_State; objindex: Integer): Integer; cdecl; -function lua_setfenv(L: Plua_State; idx: Integer): Integer; cdecl; - -(* -** `load' and `call' functions (load and run Lua code) -*) -procedure lua_call(L: Plua_State; nargs, nresults: Integer); cdecl; -function lua_pcall(L: Plua_State; nargs, nresults, errf: Integer): Integer; cdecl; -function lua_cpcall(L: Plua_State; func: lua_CFunction; ud: Pointer): Integer; cdecl; -function lua_load(L: Plua_State; reader: lua_Reader; dt: Pointer; const chunkname: PChar): Integer; cdecl; - -function lua_dump(L: Plua_State; writer: lua_Writer; data: Pointer): Integer; cdecl; - -(* -** coroutine functions -*) -function lua_yield(L: Plua_State; nresults: Integer): Integer; cdecl; -function lua_resume(L: Plua_State; narg: Integer): Integer; cdecl; -function lua_status(L: Plua_State): Integer; cdecl; - -(* -** Garbage-collection functions and options -*) -const - LUA_GCSTOP = 0; - LUA_GCRESTART = 1; - LUA_GCCOLLECT = 2; - LUA_GCCOUNT = 3; - LUA_GCCOUNTB = 4; - LUA_GCSTEP = 5; - LUA_GCSETPAUSE = 6; - LUA_GCSETSTEPMUL = 7; - -function lua_gc(L: Plua_State; what, data: Integer): Integer; cdecl; - -(* -** miscellaneous functions -*) -function lua_error(L: Plua_State): Integer; cdecl; - -function lua_next(L: Plua_State; idx: Integer): Integer; cdecl; - -procedure lua_concat(L: Plua_State; n: Integer); cdecl; - -function lua_getallocf(L: Plua_State; ud: PPointer): lua_Alloc; cdecl; -procedure lua_setallocf(L: Plua_State; f: lua_Alloc; ud: Pointer); cdecl; - -(* -** =============================================================== -** some useful macros -** =============================================================== -*) - -procedure lua_pop(L: Plua_State; n: Integer); - -procedure lua_newtable(L: Plua_state); - -procedure lua_register(L: Plua_State; const n: PChar; f: lua_CFunction); -procedure lua_pushcfunction(L: Plua_State; f: lua_CFunction); - -function lua_strlen(L: Plua_state; i: Integer): size_t; - -function lua_isfunction(L: Plua_State; n: Integer): Boolean; -function lua_istable(L: Plua_State; n: Integer): Boolean; -function lua_islightuserdata(L: Plua_State; n: Integer): Boolean; -function lua_isnil(L: Plua_State; n: Integer): Boolean; -function lua_isboolean(L: Plua_State; n: Integer): Boolean; -function lua_isthread(L: Plua_State; n: Integer): Boolean; -function lua_isnone(L: Plua_State; n: Integer): Boolean; -function lua_isnoneornil(L: Plua_State; n: Integer): Boolean; - -procedure lua_pushliteral(L: Plua_State; s: PChar); - -procedure lua_setglobal(L: Plua_State; const s: PChar); -procedure lua_getglobal(L: Plua_State; const s: PChar); - -function lua_tostring(L: Plua_State; i: Integer): PChar; - -(* -** compatibility macros and functions -*) - -procedure lua_getregistry(L: Plua_State); - -function lua_getgccount(L: Plua_State): Integer; - -type - lua_Chunkreader = lua_Reader; - lua_Chunkwriter = lua_Writer; - -(* -** {====================================================================== -** Debug API -** ======================================================================= -*) - -const - LUA_HOOKCALL = 0; - LUA_HOOKRET = 1; - LUA_HOOKLINE = 2; - LUA_HOOKCOUNT = 3; - LUA_HOOKTAILRET = 4; - -const - LUA_MASKCALL = 1 shl Ord(LUA_HOOKCALL); - LUA_MASKRET = 1 shl Ord(LUA_HOOKRET); - LUA_MASKLINE = 1 shl Ord(LUA_HOOKLINE); - LUA_MASKCOUNT = 1 shl Ord(LUA_HOOKCOUNT); - -const - LUA_IDSIZE = 60; - -type - lua_Debug = record (* activation record *) - event: Integer; - name: PChar; (* (n) *) - namewhat: PChar; (* (n) `global', `local', `field', `method' *) - what: PChar; (* (S) `Lua', `C', `main', `tail'*) - source: PChar; (* (S) *) - currentline: Integer; (* (l) *) - nups: Integer; (* (u) number of upvalues *) - linedefined: Integer; (* (S) *) - lastlinedefined: Integer; (* (S) *) - short_src: array[0..LUA_IDSIZE - 1] of Char; (* (S) *) - (* private part *) - i_ci: Integer; (* active function *) - end; - Plua_Debug = ^lua_Debug; - - lua_Hook = procedure(L: Plua_State; ar: Plua_Debug); cdecl; - -function lua_getstack(L: Plua_State; level: Integer; ar: Plua_Debug): Integer; cdecl; -function lua_getinfo(L: Plua_State; const what: PChar; ar: Plua_Debug): Integer; cdecl; -function lua_getlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PChar; cdecl; -function lua_setlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PChar; cdecl; -function lua_getupvalue(L: Plua_State; funcindex: Integer; n: Integer): PChar; cdecl; -function lua_setupvalue(L: Plua_State; funcindex: Integer; n: Integer): PChar; cdecl; - -function lua_sethook(L: Plua_State; func: lua_Hook; mask: Integer; count: Integer): Integer; cdecl; -//function lua_gethook(L: Plua_State): lua_Hook; cdecl; -function lua_gethookmask(L: Plua_State): Integer; cdecl; -function lua_gethookcount(L: Plua_State): Integer; cdecl; - -implementation - -function lua_upvalueindex(I: Integer): Integer; -begin - Result := LUA_GLOBALSINDEX - i; -end; - -function lua_newstate(f: lua_Alloc; ud: Pointer): Plua_State; cdecl; external LUA_NAME; -procedure lua_close(L: Plua_State); cdecl; external LUA_NAME; -function lua_newthread(L: Plua_State): Plua_State; cdecl; external LUA_NAME; - -function lua_atpanic(L: Plua_State; panicf: lua_CFunction): lua_CFunction; cdecl; external LUA_NAME; - -function lua_gettop(L: Plua_State): Integer; cdecl; external LUA_NAME; -procedure lua_settop(L: Plua_State; idx: Integer); cdecl; external LUA_NAME; -procedure lua_pushvalue(L: Plua_State; Idx: Integer); cdecl; external LUA_NAME; -procedure lua_remove(L: Plua_State; idx: Integer); cdecl; external LUA_NAME; -procedure lua_insert(L: Plua_State; idx: Integer); cdecl; external LUA_NAME; -procedure lua_replace(L: Plua_State; idx: Integer); cdecl; external LUA_NAME; -function lua_checkstack(L: Plua_State; sz: Integer): LongBool; cdecl; external LUA_NAME; -procedure lua_xmove(from, to_: Plua_State; n: Integer); cdecl; external LUA_NAME; - -function lua_isnumber(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME; -function lua_isstring(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME; -function lua_iscfunction(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME; -function lua_isuserdata(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME; -function lua_type(L: Plua_State; idx: Integer): Integer; cdecl; external LUA_NAME; -function lua_typename(L: Plua_State; tp: Integer): PChar; cdecl; external LUA_NAME; - -function lua_equal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; external LUA_NAME; -function lua_rawequal(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; external LUA_NAME; -function lua_lessthan(L: Plua_State; idx1, idx2: Integer): LongBool; cdecl; external LUA_NAME; - -function lua_tonumber(L: Plua_State; idx: Integer): lua_Number; cdecl; external LUA_NAME; -function lua_tointeger(L: Plua_State; idx: Integer): lua_Integer; cdecl; external LUA_NAME; -function lua_toboolean(L: Plua_State; idx: Integer): LongBool; cdecl; external LUA_NAME; -function lua_tolstring(L: Plua_State; idx: Integer; len: Psize_t): PChar; cdecl; external LUA_NAME; -function lua_objlen(L: Plua_State; idx: Integer): size_t; cdecl; external LUA_NAME; -function lua_tocfunction(L: Plua_State; idx: Integer): lua_CFunction; cdecl; external LUA_NAME; -function lua_touserdata(L: Plua_State; idx: Integer): Pointer; cdecl; external LUA_NAME; -function lua_tothread(L: Plua_State; idx: Integer): Plua_State; cdecl; external LUA_NAME; -function lua_topointer(L: Plua_State; idx: Integer): Pointer; cdecl; external LUA_NAME; - -procedure lua_pushnil(L: Plua_State); cdecl; external LUA_NAME; -procedure lua_pushnumber(L: Plua_State; n: lua_Number); cdecl; external LUA_NAME; -procedure lua_pushinteger(L: Plua_State; n: lua_Integer); cdecl; external LUA_NAME; -procedure lua_pushlstring(L: Plua_State; const s: PChar; l_: size_t); cdecl; external LUA_NAME; -procedure lua_pushstring(L: Plua_State; const s: PChar); cdecl; external LUA_NAME; -function lua_pushvfstring(L: Plua_State; const fmt: PChar; argp: Pointer): PChar; cdecl; external LUA_NAME; -function lua_pushfstring(L: Plua_State; const fmt: PChar): PChar; cdecl; varargs; external LUA_NAME; -procedure lua_pushcclosure(L: Plua_State; fn: lua_CFunction; n: Integer); cdecl; external LUA_NAME; -procedure lua_pushboolean(L: Plua_State; b: LongBool); cdecl; external LUA_NAME; -procedure lua_pushlightuserdata(L: Plua_State; p: Pointer); cdecl; external LUA_NAME; -procedure lua_pushthread(L: Plua_State); cdecl; external LUA_NAME; - -procedure lua_gettable(L: Plua_State; idx: Integer); cdecl; external LUA_NAME; -procedure lua_getfield(L: Plua_state; idx: Integer; k: PChar); cdecl; external LUA_NAME; -procedure lua_rawget(L: Plua_State; idx: Integer); cdecl; external LUA_NAME; -procedure lua_rawgeti(L: Plua_State; idx, n: Integer); cdecl; external LUA_NAME; -procedure lua_createtable(L: Plua_State; narr, nrec: Integer); cdecl; external LUA_NAME; -function lua_newuserdata(L: Plua_State; sz: size_t): Pointer; cdecl; external LUA_NAME; -function lua_getmetatable(L: Plua_State; objindex: Integer): Integer; cdecl; external LUA_NAME; -procedure lua_getfenv(L: Plua_State; idx: Integer); cdecl; external LUA_NAME; - -procedure lua_settable(L: Plua_State; idx: Integer); cdecl; external LUA_NAME; -procedure lua_setfield(L: Plua_State; idx: Integer; k: PChar); cdecl; external LUA_NAME; -procedure lua_rawset(L: Plua_State; idx: Integer); cdecl; external LUA_NAME; -procedure lua_rawseti(L: Plua_State; idx, n: Integer); cdecl; external LUA_NAME; -function lua_setmetatable(L: Plua_State; objindex: Integer): Integer; cdecl; external LUA_NAME; -function lua_setfenv(L: Plua_State; idx: Integer): Integer; cdecl; external LUA_NAME; - -procedure lua_call(L: Plua_State; nargs, nresults: Integer); cdecl; external LUA_NAME; -function lua_pcall(L: Plua_State; nargs, nresults, errf: Integer): Integer; cdecl; external LUA_NAME; -function lua_cpcall(L: Plua_State; func: lua_CFunction; ud: Pointer): Integer; cdecl; external LUA_NAME; -function lua_load(L: Plua_State; reader: lua_Reader; dt: Pointer; const chunkname: PChar): Integer; cdecl; external LUA_NAME; - -function lua_dump(L: Plua_State; writer: lua_Writer; data: Pointer): Integer; cdecl; external LUA_NAME; - -function lua_yield(L: Plua_State; nresults: Integer): Integer; cdecl; external LUA_NAME; -function lua_resume(L: Plua_State; narg: Integer): Integer; cdecl; external LUA_NAME; -function lua_status(L: Plua_State): Integer; cdecl; external LUA_NAME; - -function lua_gc(L: Plua_State; what, data: Integer): Integer; cdecl; external LUA_NAME; - -function lua_error(L: Plua_State): Integer; cdecl; external LUA_NAME; -function lua_next(L: Plua_State; idx: Integer): Integer; cdecl; external LUA_NAME; -procedure lua_concat(L: Plua_State; n: Integer); cdecl; external LUA_NAME; - -function lua_getallocf(L: Plua_State; ud: PPointer): lua_Alloc; cdecl; external LUA_NAME; -procedure lua_setallocf(L: Plua_State; f: lua_Alloc; ud: Pointer); cdecl; external LUA_NAME; - -procedure lua_pop(L: Plua_State; n: Integer); -begin - lua_settop(L, -n - 1); -end; - -procedure lua_newtable(L: Plua_State); -begin - lua_createtable(L, 0, 0); -end; - -procedure lua_register(L: Plua_State; const n: PChar; f: lua_CFunction); -begin - lua_pushcfunction(L, f); - lua_setglobal(L, n); -end; - -procedure lua_pushcfunction(L: Plua_State; f: lua_CFunction); -begin - lua_pushcclosure(L, f, 0); -end; - -function lua_strlen(L: Plua_State; i: Integer): size_t; -begin - Result := lua_objlen(L, i); -end; - -function lua_isfunction(L: Plua_State; n: Integer): Boolean; -begin - Result := lua_type(L, n) = LUA_TFUNCTION; -end; - -function lua_istable(L: Plua_State; n: Integer): Boolean; -begin - Result := lua_type(L, n) = LUA_TTABLE; -end; - -function lua_islightuserdata(L: Plua_State; n: Integer): Boolean; -begin - Result := lua_type(L, n) = LUA_TLIGHTUSERDATA; -end; - -function lua_isnil(L: Plua_State; n: Integer): Boolean; -begin - Result := lua_type(L, n) = LUA_TNIL; -end; - -function lua_isboolean(L: Plua_State; n: Integer): Boolean; -begin - Result := lua_type(L, n) = LUA_TBOOLEAN; -end; - -function lua_isthread(L: Plua_State; n: Integer): Boolean; -begin - Result := lua_type(L, n) = LUA_TTHREAD; -end; - -function lua_isnone(L: Plua_State; n: Integer): Boolean; -begin - Result := lua_type(L, n) = LUA_TNONE; -end; - -function lua_isnoneornil(L: Plua_State; n: Integer): Boolean; -begin - Result := lua_type(L, n) <= 0; -end; - -procedure lua_pushliteral(L: Plua_State; s: PChar); -begin - lua_pushlstring(L, s, Length(s)); -end; - -procedure lua_setglobal(L: Plua_State; const s: PChar); -begin - lua_setfield(L, LUA_GLOBALSINDEX, s); -end; - -procedure lua_getglobal(L: Plua_State; const s: PChar); -begin - lua_getfield(L, LUA_GLOBALSINDEX, s); -end; - -function lua_tostring(L: Plua_State; i: Integer): PChar; -begin - Result := lua_tolstring(L, i, nil); -end; - - -procedure lua_getregistry(L: Plua_State); -begin - lua_pushvalue(L, LUA_REGISTRYINDEX); -end; - -function lua_getgccount(L: Plua_State): Integer; -begin - Result := lua_gc(L, LUA_GCCOUNT, 0); -end; - -(* -** {====================================================================== -** Debug API -** ======================================================================= -*) - -function lua_getstack(L: Plua_State; level: Integer; ar: Plua_Debug): Integer; cdecl; external LUA_NAME; -function lua_getinfo(L: Plua_State; const what: PChar; ar: Plua_Debug): Integer; cdecl; external LUA_NAME; -function lua_getlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PChar; cdecl; external LUA_NAME; -function lua_setlocal(L: Plua_State; const ar: Plua_Debug; n: Integer): PChar; cdecl; external LUA_NAME; -function lua_getupvalue(L: Plua_State; funcindex: Integer; n: Integer): PChar; cdecl; external LUA_NAME; -function lua_setupvalue(L: Plua_State; funcindex: Integer; n: Integer): PChar; cdecl; external LUA_NAME; -function lua_sethook(L: Plua_State; func: lua_Hook; mask: Integer; count: Integer): Integer; cdecl; external LUA_NAME; -//function lua_gethook(L: Plua_State): lua_Hook; cdecl; external LUA_NAME; -function lua_gethookmask(L: Plua_State): Integer; cdecl; external LUA_NAME; -function lua_gethookcount(L: Plua_State): Integer; cdecl; external LUA_NAME; -(****************************************************************************** -* Copyright (C) 1994-2003 Tecgraf, PUC-Rio. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -******************************************************************************) -end. diff --git a/src/lib/lua/lualib.pas b/src/lib/lua/lualib.pas deleted file mode 100644 index 64ec473..0000000 --- a/src/lib/lua/lualib.pas +++ /dev/null @@ -1,106 +0,0 @@ -(****************************************************************************** - * * - * File: lualib.pas * - * Authors: TeCGraf (C headers + actual Lua libraries) * - * Lavergne Thomas (original translation to Pascal) * - * Bram Kuijvenhoven (update to Lua 5.1.1 for FreePascal) * - * Description: Standard Lua libraries * - * * - ******************************************************************************) - -(* -** $Id: lualib.h,v 1.28 2003/03/18 12:24:26 roberto Exp $ -** Lua standard libraries -** See Copyright Notice in lua.h -*) -(* -** Translated to pascal by Lavergne Thomas -** Bug reports : -** - thomas.lavergne@laposte.net -** In french or in english -*) - -{$IFDEF FPC}{$MODE OBJFPC}{$H+}{$ENDIF} - -unit lualib; - -interface - -uses - Lua; - -const - LUA_COLIBNAME = 'coroutine'; - LUA_TABLIBNAME = 'table'; - LUA_IOLIBNAME = 'io'; - LUA_OSLIBNAME = 'os'; - LUA_STRLIBNAME = 'string'; - LUA_MATHLIBNAME = 'math'; - LUA_DBLIBNAME = 'debug'; - LUA_LOADLIBNAME = 'package'; - -function luaopen_base(L: Plua_State): Integer; cdecl; -function luaopen_table(L: Plua_State): Integer; cdecl; -function luaopen_io(L: Plua_State): Integer; cdecl; -function luaopen_os(L: Plua_State): Integer; cdecl; -function luaopen_string(L: Plua_State): Integer; cdecl; -function luaopen_math(L: Plua_State): Integer; cdecl; -function luaopen_debug(L: Plua_State): Integer; cdecl; -function luaopen_package(L: Plua_State): Integer; cdecl; - -(* open all previous libraries *) -procedure luaL_openlibs(L: Plua_State); cdecl; - -(* compatibility code *) - -function lua_baselibopen(L: Plua_State): LongBool; -function lua_tablibopen(L: Plua_State): LongBool; -function lua_iolibopen(L: Plua_State): LongBool; -function lua_strlibopen(L: Plua_State): LongBool; -function lua_mathlibopen(L: Plua_State): LongBool; -function lua_dblibopen(L: Plua_State): LongBool; - -implementation - -function luaopen_base(L: Plua_State): Integer; cdecl; external LUA_LIB_NAME; -function luaopen_table(L: Plua_State): Integer; cdecl; external LUA_LIB_NAME; -function luaopen_io(L: Plua_State): Integer; cdecl; external LUA_LIB_NAME; -function luaopen_os(L: Plua_State): Integer; cdecl; external LUA_LIB_NAME; -function luaopen_string(L: Plua_State): Integer; cdecl; external LUA_LIB_NAME; -function luaopen_math(L: Plua_State): Integer; cdecl; external LUA_LIB_NAME; -function luaopen_debug(L: Plua_State): Integer; cdecl; external LUA_LIB_NAME; -function luaopen_package(L: Plua_State): Integer; cdecl; external LUA_LIB_NAME; - -procedure luaL_openlibs(L: Plua_State); cdecl; external LUA_LIB_NAME; - -function lua_baselibopen(L: Plua_State): LongBool; -begin - Result := LongBool(luaopen_base(L)); -end; - -function lua_tablibopen(L: Plua_State): LongBool; -begin - Result := LongBool(luaopen_table(L)); -end; - -function lua_iolibopen(L: Plua_State): LongBool; -begin - Result := LongBool(luaopen_io(L)); -end; - -function lua_strlibopen(L: Plua_State): LongBool; -begin - Result := LongBool(luaopen_string(L)); -end; - -function lua_mathlibopen(L: Plua_State): LongBool; -begin - Result := LongBool(luaopen_math(L)); -end; - -function lua_dblibopen(L: Plua_State): LongBool; -begin - Result := LongBool(luaopen_debug(L)); -end; - -end.