Note that there are some explanatory texts on larger screens.

plurals
  1. PODelphi "array of const" to "varargs"
    primarykey
    data
    text
    <p>Please help! I need this conversion to write wrapper for some C headers for Delphi.</p> <p>As an example:</p> <pre><code>function pushfstring(fmt: PAnsiChar): PAnsiChar; cdecl; varargs; external; ... function PushString(fmt: AnsiString; const args: array of const): AnsiString; begin Result := AnsiString(pushfstring(PAnsiString(fmt), args)); // it's incorrect :/ end; </code></pre> <p>How can I convert "array of const" to "varargs"?</p> <p><strong>edit</strong>: function PushString is actually inside the record (I gave a simplified example), and I do not have direct access to pushfstring. Direct call is excluded.</p> <p><strong>edit 2</strong>:I write the units for LUA library for Delphi and the case is quite important for me.</p> <p>Specifying and providing all the details of the matter - I have this function in C:</p> <pre><code>LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);</code></pre> <p>In Delphi I have something like this:</p> <p><em>LuaLibrary.pas</em></p> <pre><code>{...} interface {...} function lua_pushfstring(L: lua_State; fmt: PAnsiChar): PAnsiChar; cdecl; varargs; implementation {...} function lua_pushfstring; external 'lua.dll'; // or from OMF *.obj file by $L</code></pre> <p><em>dtxLua.pas</em></p> <pre><code>uses LuaLibrary; {...} type TLuaState = packed record private FLuaState: lua_State; public class operator Implicit(A: TLuaState): lua_State; inline; class operator Implicit(A: lua_State): TLuaState; inline; {...} // btw. PushFString can't be inline function function PushFString(fmt: PAnsiChar; const args: array of const ): PAnsiChar; //... and a lot of 'wrapper functions' for functions like a lua_pushfstring, // where L: lua_State; is the first parameter end; implementation {...} function TLuaState.PushFString(fmt: PAnsiChar; const args: array of const ) : PAnsiChar; begin Result := lua_pushfstring(FLuaState, fmt, args); // it's incorrect :/ end;</code></pre> <p>and in other units like Lua.pas i use only TLuaState from dtxLua.pas (because LuaLibrary is bulky, dtxLua is my wrapper), for many useful and cool things...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload