using System;
using System.Runtime.InteropServices;

namespace QCRPG.Framework;

internal class TclAPI
{
	public const string tclLibraryFilename = "tcl83.dll";

	public const string tclInstallDirectoryName = "tcl8.3";

	public const CallingConvention callingConvention = CallingConvention.Cdecl;

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern void Tcl_Free(IntPtr pointer);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern TclResult Tcl_GetBoolean(IntPtr interpreterPointer, string src, out int value);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern TclResult Tcl_GetDouble(IntPtr interpreterPointer, string src, out double value);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern TclResult Tcl_GetInt(IntPtr interpreterPointer, string src, out int value);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern void Tcl_AppendResult(IntPtr interpreterPointer, string result, IntPtr nullPointer);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern void Tcl_CreateCommand(IntPtr interpreterPointer, string commandName, IntPtr commandProc, IntPtr clientData, IntPtr deleteProc);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern IntPtr Tcl_CreateInterp();

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern void Tcl_DeleteInterp(IntPtr interpreterPointer);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern TclResult Tcl_Eval(IntPtr interpreterPointer, string scriptContents);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern IntPtr Tcl_GetStringResult(IntPtr interpreterPointer);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern TclResult Tcl_Init(IntPtr interpreterPointer);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern void Tcl_SetResult(IntPtr interpreterPointer, string result, TclFreeProcSpecialValue freeProc);

	[DllImport("tcl83.dll", CallingConvention = CallingConvention.Cdecl)]
	public static extern TclResult Tcl_SplitList(IntPtr interpreterPointer, string list, out int argc, out IntPtr argvPtr);
}
