View Single Post
  #13  
Unread 05-31-2014, 08:06 AM
Digpoe Digpoe is offline
The Undefeated
Interface Author - Click to view interfaces
 
Join Date: May 2014
Posts: 7
Quote:
Originally Posted by Equendil
As far as I know, packages, I/O and OS operations, and debug functions have been stripped. I don't think coroutines work either. So basically you have access to the basic (most of it), string, table and math libraries. Well, I've been checking that stuff a long time ago though. Anyway, you might want to check the global scope to see what's in there, I wrote a plugin that lets you do that within LotRO: http://www.lotrointerface.com/downlo...BeDragons.html
Quote:
Originally Posted by Thurallor
Coroutines do work, sort of. The following code
Code:
local func = coroutine.create(function(num)
    num = coroutine.yield("a" .. tostring(num));
    num = coroutine.yield("b" .. tostring(num));
    num = coroutine.yield("c" .. tostring(num));
    return "d" .. tostring(num);
end);

result, value = coroutine.resume(func, 1); Turbine.Shell.WriteLine("result = " .. tostring(result) .. "; value = " .. tostring(value));
result, value = coroutine.resume(func, 2); Turbine.Shell.WriteLine("result = " .. tostring(result) .. "; value = " .. tostring(value));
result, value = coroutine.resume(func, 3); Turbine.Shell.WriteLine("result = " .. tostring(result) .. "; value = " .. tostring(value));
result, value = coroutine.resume(func, 4); Turbine.Shell.WriteLine("result = " .. tostring(result) .. "; value = " .. tostring(value));
result, value = coroutine.resume(func, 5); Turbine.Shell.WriteLine("result = " .. tostring(result) .. "; value = " .. tostring(value));
produces the following output:
result = true; value = a1
result = true; value = b2
result = true; value = c3
result = true; value = d4
result = false; value = cannot resume dead coroutine
However, I don't think you can call any API functions within a coroutine (e.g. Turbine.Shell.WriteLine doesn't work), so it seems pretty useless. You can access global variables, though. So if you had a big number crunching task, you could put it in a coroutine that is resumed in an Update() event handler, and spread out the computations over time until complete. I haven't tried this, but it seems like it would work.

Edit: I suppose you could pass a function and arguments to coroutine.yield(), and call the function in Update() when it's returned by coroutine.resume().
Thanks for the info, guys. I did an environment dump (which was weird, because I'm used to a slightly different environment setup where I don't have to use a pairs loop on _G) and I found that a few functions are disabled;
  • loadfile
  • io and os libraries

And a few others which I probably didn't notice. :P

In fact, I'm actually surprised at how little sandboxing of the environment that LoTRO has; I can escape environment sandboxes using the __gc metamethod (I'm used to that being disabled, in fact, I hardly use it at all!) and make custom userdatas using newproxy.
__________________
Some kiddo who knows Lua
Reply With Quote