Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions gamedata/vscript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,14 @@

"IScriptVM::CompileScript" // vtable dumper got it wrong
{
"linux" "8"
"windows" "10"
"linux" "9"
"windows" "11"
}

"IScriptVM::ReleaseScript"
{
"linux" "10"
"windows" "12"
}

"IScriptVM::ExecuteFunction"
Expand Down
13 changes: 9 additions & 4 deletions scripting/include/vscript.inc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ methodmap HSCRIPT < Address

// Frees a HSCRIPT memory
public native void Release();

// Frees a HSCRIPT memory. This is only used for compiled scripts.
public native void ReleaseScript();
}

// Several functions accept null HScript as g_pScriptVM for root table
Expand Down Expand Up @@ -221,7 +224,8 @@ methodmap VScriptExecute < Handle
// Creates a new handle to execute a script function
//
// @param script Script address to execute.
public native VScriptExecute(HSCRIPT script);
// @param scope The script scope to execute the script inside of.
public native VScriptExecute(HSCRIPT script, HSCRIPT scope = HSCRIPT_RootTable);

// Adds a new parameter at the end
//
Expand Down Expand Up @@ -265,7 +269,7 @@ native void VScript_ResetScriptVM();
* @param script Script to compile
* @param id Optional ID to set
*
* @return HSCRIPT of script, null if could not compile. This MUST be freed when not in use by using HSCRIPT.Release()
* @return HSCRIPT of script, null if could not compile. This MUST be freed when not in use by using HSCRIPT.ReleaseScript().
*/
native HSCRIPT VScript_CompileScript(const char[] script, const char[] id = NULL_STRING);

Expand All @@ -274,7 +278,7 @@ native HSCRIPT VScript_CompileScript(const char[] script, const char[] id = NULL
*
* @param filepath Filepath to get a script, 'scripts/vscripts/' are automatically added to the filepath
*
* @return HSCRIPT of script, null if could not compile. This MUST be freed when not in use by using HSCRIPT.Release()
* @return HSCRIPT of script, null if could not compile. This MUST be freed when not in use by using HSCRIPT.ReleaseScript().
* @error Invalid filepath.
*/
native HSCRIPT VScript_CompileScriptFile(const char[] filepath);
Expand Down Expand Up @@ -402,7 +406,8 @@ public void __pl_vscript_SetNTVOptional()
MarkNativeAsOptional("HSCRIPT.SetValue");
MarkNativeAsOptional("HSCRIPT.SetValueString");
MarkNativeAsOptional("HSCRIPT.Release");

MarkNativeAsOptional("HSCRIPT.ReleaseScript");

MarkNativeAsOptional("VScriptFunction.GetScriptName");
MarkNativeAsOptional("VScriptFunction.GetDescription");
MarkNativeAsOptional("VScriptFunction.Binding.get");
Expand Down
12 changes: 11 additions & 1 deletion scripting/vscript.sp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int iLen
CreateNative("HSCRIPT.SetValueString", Native_HScript_SetValueString);
CreateNative("HSCRIPT.SetValueVector", Native_HScript_SetValueVector);
CreateNative("HSCRIPT.Release", Native_HScript_Release);
CreateNative("HSCRIPT.ReleaseScript", Native_HScript_ReleaseScript);

CreateNative("VScriptFunction.GetScriptName", Native_Function_GetScriptName);
CreateNative("VScriptFunction.SetScriptName", Native_Function_SetScriptName);
Expand Down Expand Up @@ -223,6 +224,12 @@ public any Native_HScript_Release(Handle hPlugin, int iNumParams)
return 0;
}

public any Native_HScript_ReleaseScript(Handle hPlugin, int iNumParams)
{
HScript_ReleaseScript(GetNativeCell(1));
return 0;
}

public any Native_Function_GetScriptName(Handle hPlugin, int iNumParams)
{
int iLength = GetNativeCell(3);
Expand Down Expand Up @@ -398,7 +405,10 @@ public any Native_Class_CreateFunction(Handle hPlugin, int iNumParams)

public any Native_Execute(Handle hPlugin, int iNumParams)
{
VScriptExecute aExecute = Execute_Create(GetNativeCell(1));
HSCRIPT hScript = GetNativeCell(1);
HSCRIPT hScope = iNumParams > 1 ? GetNativeCell(2) : HSCRIPT_RootTable;

VScriptExecute aExecute = Execute_Create(hScript, hScope);

VScriptExecute aClone = view_as<VScriptExecute>(CloneHandle(aExecute, hPlugin));
delete aExecute;
Expand Down
8 changes: 4 additions & 4 deletions scripting/vscript/execute.sp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum struct Execute
{
HSCRIPT pHScript;
ExecuteParam nReturn;
HSCRIPT hScope;
}

static Handle g_hSDKCallExecuteFunction;
Expand All @@ -20,14 +21,13 @@ void Execute_LoadGamedata(GameData hGameData)
g_hSDKCallExecuteFunction = CreateSDKCall(hGameData, "IScriptVM", "ExecuteFunction", SDKType_PlainOldData, SDKType_PlainOldData, SDKType_PlainOldData, SDKType_PlainOldData, SDKType_PlainOldData, SDKType_PlainOldData, SDKType_Bool);
}

/* TODO execute a function from a scope, so we can pass scope param */

VScriptExecute Execute_Create(HSCRIPT pHScript)
VScriptExecute Execute_Create(HSCRIPT pHScript, HSCRIPT hScope)
{
ArrayList aExecute = new ArrayList(sizeof(Execute));

Execute execute;
execute.pHScript = pHScript;
execute.hScope = hScope;
aExecute.PushArray(execute);
return view_as<VScriptExecute>(aExecute);
}
Expand Down Expand Up @@ -101,7 +101,7 @@ ScriptStatus_t Execute_Execute(VScriptExecute aExecute)
hArgs.StoreToOffset((iParam * g_iScriptVariant_sizeof) + g_iScriptVariant_union, nValue, NumberType_Int32);
}

ScriptStatus_t nStatus = SDKCall(g_hSDKCallExecuteFunction, GetScriptVM(), execute.pHScript, hArgs ? hArgs.Address : Address_Null, iNumParams, pReturn.Address, 0, true);
ScriptStatus_t nStatus = SDKCall(g_hSDKCallExecuteFunction, GetScriptVM(), execute.pHScript, hArgs ? hArgs.Address : Address_Null, iNumParams, pReturn.Address, execute.hScope, true);

execute.nReturn.nType = pReturn.nType;
execute.nReturn.nValue = pReturn.nValue;
Expand Down
7 changes: 7 additions & 0 deletions scripting/vscript/hscript.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ static Handle g_hSDKCallGetValue;
static Handle g_hSDKCallSetValueString;
static Handle g_hSDKCallSetValue;
static Handle g_hSDKCallReleaseValue;
static Handle g_hSDKCallReleaseScript;

void HScript_LoadGamedata(GameData hGameData)
{
Expand All @@ -13,6 +14,7 @@ void HScript_LoadGamedata(GameData hGameData)
g_hSDKCallSetValueString = CreateSDKCall(hGameData, "IScriptVM", "SetValueString", SDKType_Bool, SDKType_PlainOldData, SDKType_String, SDKType_String);
g_hSDKCallSetValue = CreateSDKCall(hGameData, "IScriptVM", "SetValue", SDKType_Bool, SDKType_PlainOldData, SDKType_String, SDKType_PlainOldData);
g_hSDKCallReleaseValue = CreateSDKCall(hGameData, "IScriptVM", "ReleaseValue", _, SDKType_PlainOldData);
g_hSDKCallReleaseScript = CreateSDKCall(hGameData, "IScriptVM", "ReleaseScript", _, SDKType_PlainOldData);
}

HSCRIPT HScript_CreateTable()
Expand Down Expand Up @@ -154,3 +156,8 @@ void HScript_ReleaseValue(HSCRIPT pHScript)
SDKCall(g_hSDKCallReleaseValue, GetScriptVM(), pValue.Address);
delete pValue;
}

void HScript_ReleaseScript(HSCRIPT pHScript)
{
SDKCall(g_hSDKCallReleaseScript, GetScriptVM(), pHScript);
}