lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Feb 13, 2008 6:08 AM, Fabio Mascarenhas <> wrote:
> On Feb 13, 2008 9:14 AM, Bradley Smith <> wrote:

> > How do you pass in arrays of values? For example, passing in and getting
> > out values for the C function "void list(char** strings)".

> I am adding arrays to the next version, which will let you do that:

If you just can't wait, here's a thought:

require "alien"

local glib = alien.load("glib-2.0")
local v,p,i,s = "void","pointer","int","string"

glib.g_strsplit:types(p,s,s,i) -- string to array
glib.g_strjoinv:types(s,s,p) -- array to string
glib.g_strv_length:types(i,p) -- length of array
glib.g_strfreev:types(v,p) -- free array

local delim = "\n"

local strings = {"foo", "bar", "baz"}

local lines=table.concat(strings, delim)
local strv=glib.g_strsplit(lines,delim,0)
print("length:", glib.g_strv_length(strv))

local result=glib.g_strjoinv(delim,strv)



 - Jeff