lua-users home
lua-l archive

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


We are currently working on a project where we are supposed to make certain C-functions available in lua. Just recently we ran into a problem when trying to call a function which requires an address to a pointer as one of the input arguments, such as function(int x, int y, root** p). We have registered it successfully and made it available in lua but the main problem arrises when trying to call this function with a variable created in lua like this:


Now this gives an error according to the underlying implementation since the variable log is null. We would like to call the function with a correct input parameter which would be the "address" to log and not the actual value.

We have currently created a temporary solution to this problem by creating a utility function in C which basically returns the address to a pointer of the correct type.

root** temp() {
  return (root**) &p;

If we call temp() from lua and use the return value as an input argument to our other function it returns successfully. We would ofcourse like to avoid this rather dull approach and call the function immediately from lua without first fetching the arguments from C. We have just started learning lua but is there any way of obtaining the address to a variable in lua in or to create userdata immediately in lua?

// Lyte

Windows Live Messenger är här!