MinElv
|
  |
| Joined: 10 Dec 2012 |
| Total Posts: 32 |
|
|
| 16 Jan 2013 01:45 PM |
roblox use below as wait?
[[
local stf=require'socket';
wait=stf.sleep;
]] |
|
|
| Report Abuse |
|
|
kholech
|
  |
| Joined: 18 Dec 2009 |
| Total Posts: 1135 |
|
|
| 16 Jan 2013 01:49 PM |
| wait is not a function, and this doesn't look like lua. |
|
|
| Report Abuse |
|
|
MinElv
|
  |
| Joined: 10 Dec 2012 |
| Total Posts: 32 |
|
|
| 16 Jan 2013 01:51 PM |
| eh... lua's syntax is flexible if you don't know |
|
|
| Report Abuse |
|
|
kholech
|
  |
| Joined: 18 Dec 2009 |
| Total Posts: 1135 |
|
| |
|
MinElv
|
  |
| Joined: 10 Dec 2012 |
| Total Posts: 32 |
|
|
| 16 Jan 2013 01:55 PM |
[[
stf=require'socket';
wait=function(t) local now=os.clock(); stf.sleep(t); return os.clock()-now; end;
]]
loaoALO |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2013 01:57 PM |
| It's not written in Lua code. It probably directly yields and resumes the coroutine. |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2013 02:04 PM |
Roblox has this ticker called the "RunService" which has an event that fires every frame. The wait function might be built off of that.
r=game:GetService("RunService"); function wait(t) finishTime = time() + t or 0; repeat r.Stepped:wait(); until finishTime >= time(); end
I'm sure it's more advanced than this, but this would work for a low number of scripts. I'll bet it's much more optimised so only one connection to the runservice needs to be made. |
|
|
| Report Abuse |
|
|
MinElv
|
  |
| Joined: 10 Dec 2012 |
| Total Posts: 32 |
|
|
| 16 Jan 2013 02:10 PM |
blobby
print(reunService.Stepped());--always 0.03333333 print(wait(0.033));--something random like socket.sleep(0.033); |
|
|
| Report Abuse |
|
|
MinElv
|
  |
| Joined: 10 Dec 2012 |
| Total Posts: 32 |
|
|
| 16 Jan 2013 02:43 PM |
:3
[[
using=function(t) for n,v in next,t do local o=rawget(getfenv(),n); if(o~=nil)then print('WARNING:','"'..n..'" cross variable ('..tostring(v)..' & '..tostring(o)..')'); end; rawset(getfenv(),n,v); end; end;
using(coroutine); using(require'socket'); using(require'socket.http');
----------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------
count=0;
url='http://www.roblox.com/Forum/ShowPost.aspx?PostID=%d';
ids={87076077;86868836;86868633;86299076;};
repeat for i=1,#ids do resume(create(function() request(url:format(ids[i])); count=count+1; print(count); end)); end; until sleep(0.1);
]] |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2013 03:28 PM |
| What exactly are you trying to accomplish? |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2013 03:31 PM |
Nah, it's most likely a C-side function binded into the global table. I wrote my own Wait function for LuaJ (Java implementation of Lua, rather than C).
I just had to yield the current thread the script ran on until the time expired. |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2013 03:34 PM |
Here's what mine ended up looking like. It became a bit messy only because I decided to wrap each Lua file with a coroutine instead, since not all the Lua files ran on their own thread.
Of course, my method is a bit costly, since it spawns a new true thread alone just for the delayed wait.
public static void wait(final double t, final LuaThread thread) { (new Thread() { @Override public void run() { try { Thread.sleep((long)t); thread.resume(LuaValue.NIL); } catch(Exception e) { e.printStackTrace(); } } }).start(); } |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2013 03:36 PM |
| Neat. Just one question, what's the use in converting 't' from a double to a long? I know there's a term for this, I forgot it though. I prefer C# now instead of Java. |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2013 03:39 PM |
All numbers in Lua are seen as doubles, therefore it's easier to just convert it right to its true type when it's passed to the Java-side wait function there. Then it's converted to a 'long,' since Thread.sleep requires that.
I just noticed too that I didn't make mine a true Java-to-Lua global. But I did loop it in with this bit of Lua code:
function WaitMillis(tm) tm = tonumber(tm) tm = (tm and (tm < 0 and 0 or tm) or 0) local t = time() javaGlobal:wait(tm,thread) coroutine.yield(thread) return (time()-t) end function Wait(tm) tm = tonumber(tm) tm = (tm and (tm < 0 and 0 or tm) or 0) return WaitMillis(tomillis(tm)) end |
|
|
| Report Abuse |
|
|
MinElv
|
  |
| Joined: 10 Dec 2012 |
| Total Posts: 32 |
|
| |
|