1

I have a big problem....can't solve it. I have free pascal program and lua script.

function getString(i:integer):PChar;public; stdcall;
begin
//something to do 
Result:=strnew(PChar('newString'));
end

by passing the registration functions there is Lua implementation

ffi.cdef
[[
char*__stdcall getString(i:integer);
]]
local str =ffi.C.getString(5)
print (tostring(str))

instead of 'newString' I get address of cdata. Please anybody help me to understand this moment. How to solve it?

1 Answer 1

2

tostring is being passed an address, and so gives you the string representation of that address. You need ffi.string instead.

local str = ffi.string(ffi.C.getString(5))

Now str is a Lua string containing what was returned by your Pascal code.

Your other perhaps bigger problem is surely that you are allocating a string on the Pascal module's heap with no obvious way of deallocating it.

Sign up to request clarification or add additional context in comments.

4 Comments

Note: I know nothing of Lua and based my answer on its documentation and this answer: stackoverflow.com/questions/25597155/… So there may be syntax inaccuracies. I'm sure you know Lua so will be able to cope.
How about some detail as to what does happen. Could perfectly well be a defect in your Pascal code.
Thanks, Everything is ok ! It was other mistake ))))) Thank you
Good. Glad I wasn't going mad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.