Skip to content

Commit

Permalink
add missing funcs and use luasrc_pcall to call funcs so we dont crash
Browse files Browse the repository at this point in the history
  • Loading branch information
luttje committed Sep 29, 2024
1 parent 64b1e57 commit 60865fc
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 43 deletions.
1 change: 1 addition & 0 deletions docs/general/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Additionally, we use the following conventions:
- `Ime` (short for input method editor)
- `Init` (short for initialize)
- `Json`, `Xml`, `Html`, `Css` and other data format/language names
- `Lerp` (short for linear interpolation)
- `Obb` (short for oriented bounding box)
- `Rgb`, `Rgba`, `Hsv`, `Hsl` and other color spaces
- `Sqr` (short for square root)
Expand Down
24 changes: 0 additions & 24 deletions docs/libraries/EngineVgui/IsGameUIVisible.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Player = Players.FindByUserId
PrecacheParticleSystem = ParticleSystems.Precache
GetPredictionPlayer = Predictions.GetPredictionPlayer
IsFirstTimePredicted = Predictions.IsFirstTimePredicted
LerpAngle = Angles.Lerp
LerpVector = Vectors.Lerp

RecipientFilter = RecipientFilters.Create
Expand Down Expand Up @@ -630,6 +631,21 @@ ENTITY_META.SetColor = ENTITY_META.SetRenderColor
ENTITY_META.GetColor = ENTITY_META.GetRenderColor
ENTITY_META.GetSequenceList = ENTITY_META.GetSequences

function ENTITY_META:GetForward()
local forward, _, _ = self:GetVectors()
return forward
end

function ENTITY_META:GetRight()
local _, right, _ = self:GetVectors()
return right
end

function ENTITY_META:GetUp()
local _, _, up = self:GetVectors()
return up
end

function ENTITY_META:GetDTAngle(index)
return self:GetNetworkDataValue(_E.NETWORK_VARIABLE_TYPE.ANGLE, index)
end
Expand Down Expand Up @@ -1118,7 +1134,8 @@ else
SetMousePos = input.SetCursorPosition,
ScreenToVector = input.ScreenToWorld,
AimToVector = input.AimToVector,
IsConsoleVisible = Engines.IsConsoleVisible,
IsConsoleVisible = Engines.IsConsoleVisible,
IsGameUIVisible = EngineVgui.IsGameUiVisible,
}

cam = {
Expand Down Expand Up @@ -1291,7 +1308,9 @@ else

local LABEL_PANEL_META = FindMetaTable("Label")
LABEL_PANEL_META._OriginalSetFont = LABEL_PANEL_META._OriginalSetFont or LABEL_PANEL_META.SetFont
LABEL_PANEL_META._OriginalGetFont = LABEL_PANEL_META._OriginalGetFont or LABEL_PANEL_META.GetFont
LABEL_PANEL_META._OriginalGetFont = LABEL_PANEL_META._OriginalGetFont or LABEL_PANEL_META.GetFont
LABEL_PANEL_META.SetTextColor = LABEL_PANEL_META.SetForegroundColor
LABEL_PANEL_META.GetTextColor = LABEL_PANEL_META.GetForegroundColor
LABEL_PANEL_META._OriginalSetContentAlignment = LABEL_PANEL_META._OriginalSetContentAlignment or
LABEL_PANEL_META.SetContentAlignment

Expand Down
2 changes: 1 addition & 1 deletion src/public/lgametrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ bool CTraceLuaFilter::ShouldHitEntity( IHandleEntity *pHandleEntity, int content
{
lua_pushvalue( m_pLuaState, m_iFilterArgIndex );
CBaseEntity::PushLuaInstanceSafe( m_pLuaState, EntityFromEntityHandle( pHandleEntity ) );
lua_call( m_pLuaState, 1, 1 );
luasrc_pcall( m_pLuaState, 1, 1 );

if ( lua_isboolean( m_pLuaState, -1 ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/public/lienginevgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ LUA_BINDING_BEGIN( EngineVgui, GetPanel, "library", "Get a VGUI panel instance b
}
LUA_BINDING_END( "VPanel", "The VGUI panel instance." )

LUA_BINDING_BEGIN( EngineVgui, IsGameUIVisible, "library", "Check if the game UI is currently visible." )
LUA_BINDING_BEGIN( EngineVgui, IsGameUiVisible, "library", "Check if the game UI is currently visible." )
{
lua_pushboolean( L, enginevgui->IsGameUIVisible() );
return 1;
Expand Down
28 changes: 14 additions & 14 deletions src/public/lsounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,16 @@ void CPlayUrlCallbackData::Release()
lua_unref( L, callbackRef );
}

void CALLBACK CallLuaBlockDownloadedCallback( const void *buffer, DWORD length, void *user )
{
CPlayUrlCallbackData *callbackData = ( CPlayUrlCallbackData * )user;
lua_State *L = callbackData->L;
int callbackRef = callbackData->callbackRef;

lua_rawgeti( L, LUA_REGISTRYINDEX, callbackRef );
lua_pushlstring( L, ( const char * )buffer, length );
lua_call( L, 1, 0 );
}
//void CALLBACK CallLuaBlockDownloadedCallback( const void *buffer, DWORD length, void *user )
//{
// CPlayUrlCallbackData *callbackData = ( CPlayUrlCallbackData * )user;
// lua_State *L = callbackData->L;
// int callbackRef = callbackData->callbackRef;
//
// lua_rawgeti( L, LUA_REGISTRYINDEX, callbackRef );
// lua_pushlstring( L, ( const char * )buffer, length );
// luasrc_pcall( L, 1, 0 );
//}

// E.g: lua_run_menu Sounds.PlayUrl("https://www2.cs.uic.edu/~i101/SoundFiles/StarWars3.wav")
LUA_BINDING_BEGIN( Sounds, PlayUrl, "library", "Plays a sound from a URL.", "client" )
Expand Down Expand Up @@ -628,15 +628,15 @@ LUA_BINDING_BEGIN( Sounds, PlayUrl, "library", "Plays a sound from a URL.", "cli
lua_pushaudiochannel( L, audioChannel );
lua_pushnil( L ); // TODO: implement errorId
lua_pushnil( L ); // TODO: implement errorString
lua_call( L, 3, 0 ); // Call the callback that is on the stack
luasrc_pcall( L, 3, 0 ); // Call the callback that is on the stack

return 0;
}

lua_pushaudiochannel( L, audioChannel );
lua_pushnil( L ); // TODO: implement errorId
lua_pushnil( L ); // TODO: implement errorString
lua_call( L, 3, 0 ); // Call the callback that is on the stack
luasrc_pcall( L, 3, 0 ); // Call the callback that is on the stack

return 0;
}
Expand Down Expand Up @@ -690,15 +690,15 @@ LUA_BINDING_BEGIN( Sounds, PlayFile, "library", "Plays a sound from a file.", "c
lua_pushaudiochannel( L, audioChannel );
lua_pushnil( L ); // TODO: implement errorId
lua_pushnil( L ); // TODO: implement errorString
lua_call( L, 3, 0 );
luasrc_pcall( L, 3, 0 );

return 0;
}

lua_pushaudiochannel( L, audioChannel );
lua_pushnil( L ); // TODO: implement errorId
lua_pushnil( L ); // TODO: implement errorString
lua_call( L, 3, 0 ); // Call the callback that is on the stack
luasrc_pcall( L, 3, 0 ); // Call the callback that is on the stack

return 0;
}
Expand Down
10 changes: 10 additions & 0 deletions src/public/mathlib/langle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ LUA_BINDING_BEGIN( Angles, Create, "library", "Creates a new angle." )
}
LUA_BINDING_END( "Angle", "The created angle." )

LUA_BINDING_BEGIN( Angles, Lerp, "library", "Linearly interpolates between two angles." )
{
float fraction = LUA_BINDING_ARGUMENT( luaL_checknumber, 1, "fraction" );
lua_QAngle angleStart = LUA_BINDING_ARGUMENT( luaL_checkangle, 2, "angleStart" );
lua_QAngle angleEnd = LUA_BINDING_ARGUMENT( luaL_checkangle, 3, "angleEnd" );
lua_pushangle( L, Lerp< QAngle >( fraction, angleStart, angleEnd ) );
return 1;
}
LUA_BINDING_END( "Angle", "The interpolated angle." )

/*
** Open QAngle object
*/
Expand Down
3 changes: 2 additions & 1 deletion src/vgui2/vgui_controls/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,8 @@ int Panel::GetYPos()
//-----------------------------------------------------------------------------
void Panel::SetSize( int wide, int tall )
{
Assert( abs( wide ) < 32768 && abs( tall ) < 32768 );
// Experiment; Commented out this assert, because scrollable panels may be way larger than 32768
//Assert( abs( wide ) < 32768 && abs( tall ) < 32768 );
ipanel()->SetSize( GetVPanel(), wide, tall );
}

Expand Down

0 comments on commit 60865fc

Please sign in to comment.