getVarNameFromPosition: he can read the name of the Callable 92/16692/4
Sylvain GENIN [Tue, 16 Jun 2015 08:57:23 +0000 (10:57 +0200)]
fixed : test_run("graphics","bug_10298",["no_check_error_output" ]);

Change-Id: I7b4c76b54c7cd7d0a98b62669d2c4a6dc25f0604

scilab/modules/api_scilab/src/cpp/api_common.cpp

index 344272a..425cb46 100644 (file)
@@ -434,19 +434,26 @@ static SciErr getinternalVarAddress(void *_pvCtx, int _iVar, int **_piAddress)
 SciErr getVarNameFromPosition(void *_pvCtx, int _iVar, char *_pstName)
 {
     SciErr sciErr = sciErrInit();
-#if 0
-    int iNameLen = 0;
-    int iJob1 = 1;
 
-    CvNameL(&vstk_.idstk[(Top - Rhs + _iVar - 1) * 6], _pstName, &iJob1, &iNameLen);
-    if (iNameLen == 0)
+    if (_pvCtx == NULL)
     {
-        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Unable to get name of argument #%d"), "getVarNameFromPosition", _iVar);
+        addErrorMessage(&sciErr, API_ERROR_INVALID_POSITION, _("%s: bad call to %s! (1rst argument).\n"), "",
+                        "getVarNameFromPosition");
         return sciErr;
     }
 
-    _pstName[iNameLen] = '\0';
-#endif
+    GatewayStruct* pStr = (GatewayStruct*)_pvCtx;
+    typed_list in = *pStr->m_pIn;
+
+    if (in[_iVar - 1]->isCallable())
+    {
+        std::wstring pwstring = in[_iVar - 1]->getAs<types::Callable>()->getName();
+        const wchar_t* pwcName = pwstring.c_str();
+        char* pstNameTempo = wide_string_to_UTF8(pwcName);
+        strcpy(_pstName, pstNameTempo);
+        FREE(pstNameTempo);
+    }
+
     return sciErr;
 }
 /*--------------------------------------------------------------------------*/