<?xml version="1.0" encoding="UTF-8"?>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="deleteNamedVariable" xml:lang="ja">
    <refnamediv>
        <refname>deleteNamedVariable</refname>
        <refpurpose>
            名前で指定した変数を削除する際に使用されるCゲートウェイ関数
        </refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>呼び出し手順</title>
        <synopsis>int deleteNamedVariable(void* _pvCtx, const char* _pstName)</synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>引数</title>
        <variablelist>
            <varlistentry>
                <term>_pvCtx</term>
                <listitem>
                    <para>
                        Scilab環境ポインタ, api_scilab.hで定義される "pvApiCtx" を指定
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>_pstName</term>
                <listitem>
                    <para>
                        変数名.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>説明</title>
        <para>
            名前で指定した変数を削除する際に使用されるCゲートウェイ関数
        </para>
    </refsection>
    <refsection>
        <title>例</title>
    </refsection>
    <refsection>
        <title>Scilabテストスクリプト</title>
        <programlisting role="code_scilab"><![CDATA[
fileData = ['#include ""api_scilab.h""'
'#include ""MALLOC.h""'
''
'int sci_deleteNamedVariable(char *fname, void* pvApiCtx)'
'{'
'    SciErr sciErr;'
'    int iRet = 0;'
'    int* piAddr = NULL;'
'    char* pstVarName = NULL;'
''
'    CheckRhs(1,1);'
'    CheckLhs(0,1);'
''
'    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);'
'    if(sciErr.iErr)'
'    {'
'        printError(&sciErr, 0);'
'        return 1;'
'    }'
''
'    if(getAllocatedSingleString(pvApiCtx, piAddr, &pstVarName))'
'    {'
'        //error'
'        return 1;'
'    }'
''
'    if(isNamedVarExist(pvApiCtx, pstVarName))'
'    {'
'        iRet = deleteNamedVariable(pvApiCtx, pstVarName);'
'    }'
''
'    createScalarBoolean(pvApiCtx, Rhs + 1, iRet);'
'    AssignOutputVariable(pvApiCtx, 1) = Rhs + 1;'
'    return 0;'
'}'];
currentPath = pwd();
mkdir(TMPDIR + "/deleteNamedVariable");
cd(TMPDIR + "/deleteNamedVariable");
mputl(fileData, "deleteNamedVariable.c");
ilib_verbose(0);
files = ['deleteNamedVariable.c'];
ilib_build('libdeleteNamedVariable', ['deleteNamedVariable', 'sci_deleteNamedVariable'], files, []);
exec loader.sce;
function test()
    assert_checkequal(exists("a"), 1);
    assert_checkequal(a, 1);
    a = 2;
    assert_checkequal(a, 2);
    assert_checktrue(deleteNamedVariable("a"));
    assert_checkequal(exists("a"), 1);
    assert_checkequal(a, 1);
endfunction
a = 1;
test();
assert_checkequal(a, 1);
deleteNamedVariable("a");
assert_checkequal(exists("a"), 0);
 ]]></programlisting>
    </refsection>
</refentry>
