generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How was the function 'unpack' made?

Previous Thread :: Next Thread 
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 07:21 PM
It returns all the values of the Table :O
Report Abuse
LocalChum is not online. LocalChum
Joined: 04 Mar 2011
Total Posts: 6906
18 Oct 2011 07:23 PM
easily done with loadstring
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 07:24 PM
Tell me how I've tryed once to make a similar function like it.
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 07:24 PM
But I've failed.
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 07:33 PM
I'm waiting... Is it that hard :o
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 07:46 PM
Come one LocalChum you said its Easily to make using loadstring. But I tryed it didn't work.

I think:
Scripers fail
or
Its Impossible
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
18 Oct 2011 07:47 PM
So will table.concat

­<'+1 Post. Ujelly?'>
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 07:51 PM
Tryed it before, Didn't work.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
18 Oct 2011 07:51 PM
function unpack(tab)
local a=table.concat(tab,',');
return loadstring(a);
end
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
18 Oct 2011 07:52 PM
static int luaB_unpack (lua_State *L) {
int i, e, n;
luaL_checktype(L, 1, LUA_TTABLE);
i = luaL_optint(L, 2, 1);
e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
n = e - i + 1; /* number of elements */
if (n <= 0) return 0; /* empty range */
luaL_checkstack(L, n, "table too big to unpack");
for (; i<=e; i++) /* push arg[i...e] */
lua_rawgeti(L, 1, i);
return n;
}
Report Abuse
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
18 Oct 2011 07:53 PM
With a clever approach you can indeed write the unpack function using pure idiomatic Lua:
function unpack_int(tb, i, max, ...)
if i <= max then
return unpack_int(tb, i+1, max, tb[max-i+1], ...)
else
return ...
end
end
function unpack(tb)
return unpack_int(tb, 1, #tb)
end
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 07:59 PM
SDuke524 Thnx for helping, But yours fail.
Oh ok i understand now, Thnx for helping xLEGOx, Yours work perfect.
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
18 Oct 2011 08:07 PM
xLEGOx,

how does that work when the max stack size is like 250 registers ?

local t = {};

for i = 1, 1000 do
t[i] = true;
end

print(select("#", unpack(t))); --> 1000

how does one lua prototype pass or return 1000 arguments...
/confuzzed
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
18 Oct 2011 08:13 PM
x={"Hai","One","Two"}

function unpackt(t,n)
newx={}
if table.maxn(t)>=1 then
repeat n=n+1 table.insert(newx,t[n]) until rawequal(n,table.maxn(t))
end
print(table.concat(newx,' '))
newx={}
end

unpackt(x,0)

­<'+1 Post. Ujelly?'>
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
18 Oct 2011 08:14 PM
Don't ask why I used table.maxn(x) instead of #x, if you do, it's because table.maxn is obviously more cool than #t

­<'+1 Post. Ujelly?'>
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 08:18 PM
nate890 you failed but thnx for trying.

unpack returns all the Table values.

local Table = {"Ohai","Hey","Whatever","ImValue4ujelly?"}

Value1,Value2,Value3 = unpack(Table)

print(Value1,Value2,Value3)
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
18 Oct 2011 08:21 PM
Youre an idiot

­<'+1 Post. Ujelly?'>
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 08:23 PM
How?
Report Abuse
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
18 Oct 2011 08:24 PM
@Necro
The LuaVM isn't limited to 256 registers, it's only the operands of mathematical vm instructions and what not that are. So as long as you're not explicitly using 256 named arguments stuff should work just fine up to 65000 registers.
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
18 Oct 2011 08:26 PM
Nate as you see in xLEGOx unpack function, He have put all the Table values in ... and waited till the i is more than the max value of the table then he returned the ...
Report Abuse
4FH is not online. 4FH
Joined: 08 Jun 2011
Total Posts: 14
04 Nov 2011 09:14 PM
BUMP.
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
04 Nov 2011 09:15 PM
[ Content Deleted ]
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
04 Nov 2011 09:38 PM
Y U DELET SYSTME32
Report Abuse
Varp is not online. Varp
Joined: 18 Nov 2009
Total Posts: 5333
04 Nov 2011 10:32 PM
Correct me if this is wrong/horribly inefficient, but couldn't you just do:

function unpack(t,s)
s = s or 1
if(#t == s - 1)then return end
return t[s],unpack(t,s+1)
end
Report Abuse
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
04 Nov 2011 10:56 PM
Yup... almost.

Your version and my version both have their benefits. Yours only has to copy the values when unwinding, as opposed to mine which has to copy then both ways, however, mine can be tail-call optimized and yours can't.

I'm not sure which would perform better in then end when applied to really big tables, you'd have to try it out.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image