Forum

> > CS2D > Scripts > Limits in Lua tables? Need solution.
Forums overviewCS2D overview Scripts overviewLog in to reply

English Limits in Lua tables? Need solution.

4 replies
To the start Previous 1 Next To the start

old Limits in Lua tables? Need solution.

Gaios
Reviewer Off Offline

Quote
Hi, I need to send table_index to local function, but I can't add any elements with
table.insert
. I need something like this:
1
2
3
4
5
6
7
8
function xd(t)
 t = {4}
end


tab = {}
xd(tab)
print(#tab)

This function should add new element to table but it doesn't (no errors). There should be 1 element in table but it's still 0. I can't use
table.insert
because won't be good solution for me. Any ideas?

old Re: Limits in Lua tables? Need solution.

Yates
Reviewer Off Offline

Quote
What you're trying to do cannot be done like that directly, but you can use a trick by calling the function and passing the variable name.

1
2
3
4
5
6
7
8
function test(y)
    _G[y] = 5
end

x = 0
print(x) -- prints 0
test("x")
print(x) -- prints 5

There is a way to get the original variable name passed to a function from within test, but you'd have to use debug in Lua and that is not recommended.

I don't know exactly what you're trying, but maybe you can use a return instead?

http://stackoverflow.com/questions/40933174/

old Re: Limits in Lua tables? Need solution.

Starkkz
Moderator Off Offline

Quote
@user Yates: He's trying to modify the table as if it was a var pointer object. Lua doesn't support this feature though, you would have to modify your object via
rawset()
.

Either way clean it and then do the setup/copy.

old Re: Limits in Lua tables? Need solution.

Yates
Reviewer Off Offline

Quote
@user Starkkz: What I meant when I asked what he's exactly trying is the reason behind trying to do this code-wise. If I didn't know what he was actually trying I couldn't recommend him alternative solutions

old Re: Limits in Lua tables? Need solution.

Gaios
Reviewer Off Offline

Quote
@user Starkkz: Oh, that's what I need.

Thanks you guys for willingness to help!

More >
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview