lua-users home
lua-l archive

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


Well the title ain't _exactly_ on the point but it was the best I
could come up with.The problem is this:I wan't to share vars between C
and lua(see prev. post "interfacing lua to C").Vars can be of type
int,float and string(that is char *).Now for the first two there's no
problem.To avoid buffer allocation/resizing for strings though I want
to let lua do the dirty work for me.So given that for each C string
var there's an entry in the globals table (with a nil value) and
another one in another table,the proxy table:
1)Can I get a pointer to the string of a string value,the actual
string,not a copy of it or something.Won't passing this string to a C
function make a copy of it in the stack?Will the actual string(I mean
char[]) be copied as well or will the copy on the stack point to the
initial string value?Does any of this make any sense?
2)Can you think of a good place to keep the string value in an
assignment like cstring="string" so that it won't be garbage-collected
until the next assignment when it will be no longer needed?I thought
of making an extra entry in the proxy table with the key
"__cstring_str" or something and the string as a value but maybe you
can think of a more ellegant solution.
That's all folks,
Dimitris