0

It always return a String which is (at least I guess) the table identifier someone can help in anyway?

Thats my function:

function listFiles(dir)
    local ffi = require("ffi")
    ffi.cdef[[char ** PHYSFS_enumerateFiles (   const char *    dir  );]]
    local liblove = ffi.os == "Windows" and ffi.load("love") or ffi.C
    local tb={}
    tb=liblove.PHYSFS_enumerateFiles(dir)
    return tb
end

It should return me a String with filecontents of the "Dir" I pass to it, but it doesnt. Can't figure out why.

hyde
  • 60,639
  • 21
  • 115
  • 176
  • Just a note: consider always using parenthesis when you mix *and* and *or* (in any language), to avoid operator precedence related surprises. – hyde Jul 19 '15 at 08:21
  • Another thing, what is value of `dir` when you call this function, and what are actual contents of this directory? And if `dir` is relative path, also what is current working directory when you call this function? – hyde Jul 19 '15 at 08:28
  • I forget to add the "dir" to the search path. Doing this and converting the char** to char* and then to String, it would work, right? – Calandriel Jul 19 '15 at 20:26
  • I am passing this C:/Users/Josué/Desktop/love/Texture Packs/ It returns nothing. And the contents of this is a folder named default wich bunch of pngs. And if I try to enumerate it with love filesystem, it returns a table code – Calandriel Jul 19 '15 at 20:49

1 Answers1

0

You should read the reference properly. The enumeration function returns a pointer to string pointers, after the last string follows a NULL pointer. Conversion from char* to Lua string can be done with ffi.string.

Youka
  • 2,646
  • 21
  • 33