0

In lua ,im calling a function which returns a table variable that contains many parameter internally..but when i get that value i couldnt access the paramter which is present in the table. I can see the tables parameter in the original function in the form of

[[table:0x0989]] { [[table:0x23456]] str = "hello" width = 180 }, [[table:0x23489]] { str1 = "world" }

it shows like this.but when it returns once i can able to get the top address of table like [[table:0x0989]]..when i tried acessing the tables which is present inside the main table.it is showing a nil value...how do i call that ?? can anyone help me??

user748765
  • 21
  • 1
  • 2
  • 1
    your description isn't very clear. Can you put some code? – kikito May 17 '11 at 12:10
  • yes i made little bit confusion...in other way..i want to access a values returned by the function explicitly..but when i get that return values, it shows nill value....hope i make clear..please provide solution u no.. thank u – user748765 May 19 '11 at 14:21

1 Answers1

0

If I'm reading it correctly you're doing this:

function my_function ()
    --do something
    return ({a=1, b=2, c=3})
end

From that you should be able to do this:

my_table = my_function()

then

print(my_table.a) --=> 1
print(my_table.b) --=> 2
print(my_table.c) --=> 3
U319344
  • 111
  • 3
  • Hi..this gives more explanation of my issues...In lua when i read the values(table) returned by the functions ,it shows nill value..im calling that function from outside say for example function x return y end so when i read y from outside it shows nill value...but there is some field present in it..i believe..how do i access that. – user748765 May 19 '11 at 14:31
  • Can you try doing print(type(y)), before the return, where 'y' is what you are trying to return, it may not be a fault with what is returned, more that there is not a table being formed. Also, try accessing the values before returning them too and print the result, just to make sure. – U319344 May 19 '11 at 19:40
  • hi..that is working fine when i call type() before returning ..but i need to access it after returned by the func..then only i can read the values from outside rite...is it possibe to access local variable present inside the function from outside??? – user748765 May 20 '11 at 05:45
  • You wouldn't be able to access the local variable from the function without returning it first. You can't have `function my_function () local x = {a=1, b=2, c=3}; end` as due to scope, this cannot be accessed outside of the function (there are some exceptions). Would you be able to show some code of what you are trying to do? It maybe easier to help you if I can see what is wron. – U319344 May 20 '11 at 06:07