def squared(a): command = """ a = py_obj for i=1, 100000 do for j, k in ipairs(a) do if j % 2 == 0 then a[j] = a[j] - 0.01 end end end out = a """ out = luj.lua(command, python_obj = a, lua_obj = 'out', lua_call = 'luajit') return out
def lua_find_pi(n): command = """ function find_pi(n) c = 0 for i = 0,n do x = 2 * math.random() - 1 y = 2 * math.random() - 1 d = x*x + y*y if d < 1 then c = c + 1 end end return 4 * c / n end n = py_obj pi = find_pi(n) """ pi = luj.lua(command, python_obj = n, lua_obj = 'pi', lua_call = 'luajit') return float(pi)