Global lock that prevents concurrent access to it. Note how the example creates a separate LuaRuntime for each thread frombytes( '1', ( image_size, image_size), result_buffer) # use Pillow to display the image from PIL import Image image = Image. Thread( target = mandelbrot, args =( i, lua_func))įor i, lua_func in enumerate( lua_funcs) ] Results = lua_func( image_size, i + 1, thread_count) Results = * thread_count def mandelbrot( i, lua_func): char(unpack(buf, 1, p)) end return result end ''' image_size = 1280 # = 1280 x 1280 thread_count = 8 from lupa import LuaRuntime lua_funcs = [ LuaRuntime( encoding = None). return local start_line, end_line = N/total * (i-1), N/total * i - 1 for y=start_line,end_line do local Ci, b, p = y*M-1, 1, 0 for x=0,N-1 do local Cr = x*M-1.5 local Zr, Zi, Zrq, Ziq = Cr, Ci, Cr*Cr, Ci*Ci b = b + b for i=1,49 do Zi = Zr*Zi*2 + Ci Zr = Zrq-Ziq + Cr Ziq = Zi*Zi Zrq = Zr*Zr if Zrq+Ziq > 4.0 then b = b + 1 break end end if b >= 256 then p = p + 1 buf = 511 - b b = 1 end end if b ~= 1 then p = p + 1 buf = (ba-b)*bb end result = result. Protocol that should be used, Lupa provides the helper functionsĪs_attrgetter() and as_itemgetter() that restrict the view onĪn object to a certain protocol, both from Python and from inside when attribute access is required to an object Obviously, this heuristic will fail to provide the required behaviour That uses attribute access for indexing from inside Lua. Pratically all Python objects allow attribute access, so if the objectĪlso has a _getitem_ method, it is preferred when turning it Objects, Lupa employs a simple heuristic. To decide which Python protocol to use for Lua wrapped Python does, so the Lua operations obj and obj.x both map Itĭoes not distinguish between attribute access and item access like Lua supports two main protocols on objects: calling and indexing. > wrapped_type( wrapped_type) = 'function' # unwrapped Lua function True > wrapped_type( len) = 'userdata' # wrapped Python function True > wrapped_type() = 'userdata' # wrapped Python object True The binary wheels include different Lua versions as well as LuaJIT, if supported.īy default, import lupa uses the latest Lua version, but you can choose Switching between the two languages at runtime, based on the tradeoffīetween simplicity and speed. It makes itĮasy to write dynamic Lua code that accompanies dynamic Python code by Lupa is a very fast and thin wrapper around Lua or LuaJIT. Python when raw speed is required and the edit-compile-run cycle ofīinary extension modules is too heavy and too static for agile Used as primary language for large applications, but it makes for aįast, high-level and resource-friendly backup language inside of This makes real-world Lua applications harder to write Readily includes, either directly in its standard library or as third However, the Lua ecosystem lacks many of the batteries that Python With standard Lua 5.1, it's less than 400KB. Linked LuaJIT2 runtime, only weighs some 700KB on a 64 bit machine. The complete binary module of Lupa, including a statically The language runtime is very small and carefully designed forĮmbedding. Python, but LuaJIT compiles it to very fast machine code, sometimesįaster than many statically compiled languages for computational code. "Python", two from each to keep the balance. If you don't like this kind of straight forward allegory to anĮndangered species, you may also happily assume it's just anĪmalgamation of the phonetic sounds that start the words "Lua" and In Latin, "lupa" is a female wolf, as elegant and wild as it sounds.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |