News for hackers. Stuff that matters.
Re:What Lua scripting means for Wikimedia and open source by StavrosK on Monday March 18, 2013 @10:50AM (#5394489)
The good thing about Lua is that you can sandbox it entirely and set hard limits on memory/CPU time, after which the process exits. You can just give an error message if RAM grows over a limit or if it takes longer than a few secs to execute. It's pretty safe.
Re:What Lua scripting means for Wikimedia and open source by pekk on Monday March 18, 2013 @03:53PM (#5396723)
Is it possible to run a program in 'steps,' between which the state is paused?
Re:What Lua scripting means for Wikimedia and open source by fab13n on Monday March 18, 2013 @06:30PM (#5397600)
The debug lib lets you hook behaviors on line changes, entering a function and leaving it, but nothing for single bytecodes iirc.

The debug lib, allowing to take control of the whole program, is disabled in most sandboxed environments including wikipedia's.

However, bytecode instruction and line changes both are poor metrics to measure time, cpu or any other kind of resource usage. Measuring process time is relatively easy and much more accurate.

Re:What Lua scripting means for Wikimedia and open source by StavrosK on Monday March 18, 2013 @03:55PM (#5396732)
I don't think it's possible with the stock interpreter, but I'm guessing it's pretty simple to modify the interpreter to do it. Why do you ask?
Re:What Lua scripting means for Wikimedia and open source by pekk on Monday March 18, 2013 @04:07PM (#5396788)
Simple time sharing between low-priority, potentially long-running programs submitted by untrusted users.
Re:What Lua scripting means for Wikimedia and open source by StavrosK on Monday March 18, 2013 @04:09PM (#5396806)
Run a process per script and let the OS handle it, probably.
Re:What Lua scripting means for Wikimedia and open source by gngeal on Monday March 18, 2013 @05:30PM (#5397268)
You don't even need to do that, you can run Lua in a multithreaded program, as long as no lua_State is accessed from multiple threads. You can spawn independent interpreter states, have them do their job and terminate. The whole Lua codebase as such is completely stateless (apart from the state that you keep for your code). The shorter the scripts actually run, the smaller overhead you get by this.
Re:What Lua scripting means for Wikimedia and open source by pekk on Monday March 18, 2013 @06:11PM (#5397504)
That isn't what I asked about and isn't really helpful
Re:What Lua scripting means for Wikimedia and open source by StavrosK on Monday March 18, 2013 @06:20PM (#5397548)
Don't read it, I guess? I don't know any other way to do it, unfortunately. I'm sorry I wasted your time.
Re:What Lua scripting means for Wikimedia and open source by gngeal on Monday March 18, 2013 @05:25PM (#5397227)
Why not? Isn't that the whole purpose of coroutines in Lua?
Re:What Lua scripting means for Wikimedia and open source by fab13n on Monday March 18, 2013 @06:33PM (#5397616)
No, quite the contrary: coroutines only yield explicitly, due to a call to coroutine.yield(). They let you control your scheduling deterministically (although multitasking is far from being their only use)
Re:What Lua scripting means for Wikimedia and open source by gngeal on Tuesday March 19, 2013 @07:35AM (#5400227)
Note that GP didn't mention the means in which the yielding was to be invoked.
Re:What Lua scripting means for Wikimedia and open source by ufo on Monday March 18, 2013 @05:32PM (#5397284)
You can't yield if there is a C function lower down in the stack so I don't think you can always abuse the coroutine system to implement OS threads like that.
Re:What Lua scripting means for Wikimedia and open source by gngeal on Monday March 18, 2013 @06:23PM (#5397561)
Are you sure about that? I thought that yields across C functions were added in Lua 5.2. Not to mention that in a controlled environment like the runtime that Wikipedia exposes to you, you can take care of avoiding exposing APIs that would allow people to code themselves into a corner like that (if the C calls are leaves, you're OK even in 5.1).
Re:What Lua scripting means for Wikimedia and open source by ufo on Monday March 18, 2013 @11:31PM (#5398743)
You are right that they could use a carefully crafted API to work around the problems. Its also true that yields across C were added in 5.2 but you need to code the C functions in continuation-passing-style using a special API to take advantage of that.

http://www.lua.org/manual/5.2/manual.html#4.7

Re:What Lua scripting means for Wikimedia and open source by gngeal on Tuesday March 19, 2013 @07:32AM (#5400215)
Well, two other options for you are using the coco library with stock Lua 5.1.x, or simply using LuaJIT.