multiple trees
This commit is contained in:
parent
e3a8e74fff
commit
0b08fdf536
191
init.lua
191
init.lua
@ -21,46 +21,76 @@ realterrain.settings.filedem = 'dem.tif'
|
||||
realterrain.settings.filewater = 'water.tif'
|
||||
realterrain.settings.fileroads = 'roads.tif'
|
||||
realterrain.settings.filebiome = 'biomes.tif'
|
||||
|
||||
realterrain.settings.b01cut = 10
|
||||
realterrain.settings.b01ground = "default:dirt_with_grass"
|
||||
realterrain.settings.b01tree = "tree"
|
||||
realterrain.settings.b01tprob = 0.3
|
||||
realterrain.settings.b01shrub = "default:grass_1"
|
||||
realterrain.settings.b01sprob = 5
|
||||
|
||||
realterrain.settings.b02cut = 20
|
||||
realterrain.settings.b02ground = "default:dirt_with_dry_grass"
|
||||
realterrain.settings.b02tree = "tree"
|
||||
realterrain.settings.b02tprob = 0.3
|
||||
realterrain.settings.b02shrub = "default:dry_gass_1"
|
||||
realterrain.settings.b02sprob = 5
|
||||
|
||||
realterrain.settings.b03cut = 30
|
||||
realterrain.settings.b03ground = "default:sand"
|
||||
realterrain.settings.b03tree = "cactus"
|
||||
realterrain.settings.b03tprob = 0.3
|
||||
realterrain.settings.b03shrub = "default:dry_grass_1"
|
||||
realterrain.settings.b03sprob = 5
|
||||
|
||||
realterrain.settings.b04cut = 40
|
||||
realterrain.settings.b04ground = "default:gravel"
|
||||
realterrain.settings.b04tree = "cactus"
|
||||
realterrain.settings.b04tprob = 0.3
|
||||
realterrain.settings.b04shrub = "default:dry_shrub"
|
||||
realterrain.settings.b04sprob = 5
|
||||
|
||||
realterrain.settings.b05cut = 50
|
||||
realterrain.settings.b05ground = "default:clay"
|
||||
realterrain.settings.b05tree = "tree"
|
||||
realterrain.settings.b05tree = ""
|
||||
realterrain.settings.b05tprob = 0.3
|
||||
realterrain.settings.b05shrub = "default:dry_shrub"
|
||||
realterrain.settings.b05sprob = 5
|
||||
|
||||
realterrain.settings.b06cut = 60
|
||||
realterrain.settings.b06ground = "default:stone"
|
||||
realterrain.settings.b06tree = "tree"
|
||||
realterrain.settings.b06tree = ""
|
||||
realterrain.settings.b06tprob = 0.3
|
||||
realterrain.settings.b06shrub = "default:junglegrass"
|
||||
realterrain.settings.b06sprob = 5
|
||||
|
||||
realterrain.settings.b07cut = 70
|
||||
realterrain.settings.b07ground = "default:stone_with_iron"
|
||||
realterrain.settings.b07tree = "tree"
|
||||
realterrain.settings.b07tree = "jungletree"
|
||||
realterrain.settings.b07tprob = 0.3
|
||||
realterrain.settings.b07shrub = "default:junglegrass"
|
||||
realterrain.settings.b07sprob = 5
|
||||
|
||||
realterrain.settings.b08cut = 80
|
||||
realterrain.settings.b08ground = "default:stone_with_coal"
|
||||
realterrain.settings.b08tree = "tree"
|
||||
realterrain.settings.b08tree = ""
|
||||
realterrain.settings.b08tprob = 0.3
|
||||
realterrain.settings.b08shrub = "default:junglegrass"
|
||||
realterrain.settings.b08sprob = 5
|
||||
|
||||
realterrain.settings.b09cut = 90
|
||||
realterrain.settings.b09ground = "default:stone_with_copper"
|
||||
realterrain.settings.b09tree = "tree"
|
||||
realterrain.settings.b09tree = "jungletree"
|
||||
realterrain.settings.b09tprob = 0.3
|
||||
realterrain.settings.b09shrub = "default:junglegrass"
|
||||
realterrain.settings.b09sprob = 5
|
||||
|
||||
realterrain.settings.b10cut = 100
|
||||
realterrain.settings.b10ground = "default:dirt_with_snow"
|
||||
realterrain.settings.b10tree = "tree"
|
||||
realterrain.settings.b10tree = "snowtree"
|
||||
realterrain.settings.b10tprob = 0.3
|
||||
realterrain.settings.b10shrub = "default:dry_grass_1"
|
||||
realterrain.settings.b10sprob = 5
|
||||
|
||||
--called at each form submission
|
||||
function realterrain.save_settings()
|
||||
@ -106,6 +136,11 @@ end
|
||||
--read from file, various persisted settings
|
||||
realterrain.load_settings()
|
||||
|
||||
--need to override the minetest.formspec_escape to return empty string when nil
|
||||
function realterrain.esc(str)
|
||||
if str == "" or not str then return "" else return minetest.formspec_escape(str) end
|
||||
end
|
||||
|
||||
function realterrain.list_images()
|
||||
local dir = MODPATH .. "/dem/"
|
||||
local list = {}
|
||||
@ -192,39 +227,67 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
local elev, biome, water, road = realterrain.get_pixel(x, z) -- elevation in meters from DEM and water true/false
|
||||
--print("elev: "..elev..", biome: "..biome..", water: "..water..", road: "..road)
|
||||
|
||||
local ground, shrub, sprob, tprob, tree
|
||||
sprob, tprob = 5, 0.3
|
||||
tree = "tree"
|
||||
if biome < tonumber(realterrain.get_setting("b01cut")) then
|
||||
local ground, tree, tprob, shrub, sprob
|
||||
if biome < tonumber(realterrain.get_setting("b01cut")) then
|
||||
ground = cids[1].ground
|
||||
tree = realterrain.get_setting("b01tree")
|
||||
tprob = tonumber(realterrain.get_setting("b01tprob"))
|
||||
shrub = cids[1].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b01sprob"))
|
||||
elseif biome < tonumber(realterrain.get_setting("b02cut")) then
|
||||
ground = cids[2].ground
|
||||
tree = realterrain.get_setting("b02tree")
|
||||
tprob = tonumber(realterrain.get_setting("b02tprob"))
|
||||
shrub = cids[2].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b02sprob"))
|
||||
elseif biome < tonumber(realterrain.get_setting("b03cut")) then
|
||||
ground = cids[3].ground
|
||||
tree = realterrain.get_setting("b03tree")
|
||||
tprob = tonumber(realterrain.get_setting("b03tprob"))
|
||||
shrub = cids[3].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b03sprob"))
|
||||
elseif biome < tonumber(realterrain.get_setting("b04cut")) then
|
||||
ground = cids[4].ground
|
||||
tree = realterrain.get_setting("b04tree")
|
||||
tprob = tonumber(realterrain.get_setting("b04tprob"))
|
||||
shrub = cids[4].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b04sprob"))
|
||||
elseif biome < tonumber(realterrain.get_setting("b05cut")) then
|
||||
ground = cids[5].ground
|
||||
tree = realterrain.get_setting("b05tree")
|
||||
tprob = tonumber(realterrain.get_setting("b05tprob"))
|
||||
shrub = cids[5].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b05sprob"))
|
||||
elseif biome < tonumber(realterrain.get_setting("b06cut")) then
|
||||
ground = cids[6].ground
|
||||
tree = realterrain.get_setting("b06tree")
|
||||
tprob = tonumber(realterrain.get_setting("b06tprob"))
|
||||
shrub = cids[6].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b06sprob"))
|
||||
elseif biome < tonumber(realterrain.get_setting("b07cut")) then
|
||||
ground = cids[7].ground
|
||||
tree = realterrain.get_setting("b07tree")
|
||||
tprob = tonumber(realterrain.get_setting("b07tprob"))
|
||||
shrub = cids[7].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b07sprob"))
|
||||
elseif biome < tonumber(realterrain.get_setting("b08cut")) then
|
||||
ground = cids[8].ground
|
||||
tree = realterrain.get_setting("b08tree")
|
||||
tprob = tonumber(realterrain.get_setting("b08tprob"))
|
||||
shrub = cids[8].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b08sprob"))
|
||||
elseif biome < tonumber(realterrain.get_setting("b09cut")) then
|
||||
ground = cids[9].ground
|
||||
tree = realterrain.get_setting("b09tree")
|
||||
tprob = tonumber(realterrain.get_setting("b09tprob"))
|
||||
shrub = cids[9].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b09sprob"))
|
||||
elseif biome < tonumber(realterrain.get_setting("b10cut")) then
|
||||
ground = cids[10].ground
|
||||
tree = realterrain.get_setting("b10tree")
|
||||
tprob = tonumber(realterrain.get_setting("b10tprob"))
|
||||
shrub = cids[10].shrub
|
||||
sprob = tonumber(realterrain.get_setting("b10sprob"))
|
||||
end
|
||||
|
||||
local vi = area:index(x, y0, z) -- voxelmanip index
|
||||
@ -270,11 +333,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
--shrubs and trees one block above the ground
|
||||
elseif y == elev + 1 and water == 0 and road == 0 then
|
||||
if math.random(0,100) <= sprob then
|
||||
if shrub and math.random(0,100) <= sprob then
|
||||
data[vi] = shrub
|
||||
end
|
||||
if math.random(0,100) <= tprob then
|
||||
table.insert(treemap, {pos={x=x,y=y,z=z}, type="tree"})
|
||||
if tree and y < tonumber(realterrain.settings.alpinelevel) + math.random(1,5) and math.random(0,100) <= tprob then
|
||||
table.insert(treemap, {pos={x=x,y=y,z=z}, type=tree})
|
||||
end
|
||||
elseif y <= tonumber(realterrain.settings.waterlevel) then
|
||||
data[vi] = c_water
|
||||
@ -291,7 +354,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
|
||||
--place all the trees
|
||||
for k,v in next, treemap do
|
||||
minetest.place_schematic({x=v.pos.x-3,y=v.pos.y,z=v.pos.z-3}, MODPATH.."/schems/"..v.type..".mts")
|
||||
minetest.place_schematic({x=v.pos.x-3,y=v.pos.y,z=v.pos.z-3}, MODPATH.."/schems/"..v.type..".mts", (math.floor(math.random(0,3)) * 90), nil, false)
|
||||
end
|
||||
|
||||
local chugent = math.ceil((os.clock() - t0) * 1000)
|
||||
@ -413,23 +476,23 @@ function realterrain.show_rc_form(pname)
|
||||
" y= "..math.floor(ppos.y).." z= "..math.floor(ppos.z).." and mostly facing "..dir.."]"
|
||||
--Scale settings
|
||||
local f_scale_settings = "field[1,1;4,1;bits;Bit Depth;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("bits")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("bits")).."]" ..
|
||||
"field[1,2;4,1;yscale;Vertical meters per voxel;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("yscale")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("yscale")).."]" ..
|
||||
"field[1,3;4,1;xscale;East-West voxels per pixel;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("xscale")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("xscale")).."]" ..
|
||||
"field[1,4;4,1;zscale;North-South voxels per pixel;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("zscale")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("zscale")).."]" ..
|
||||
"field[1,5;4,1;waterlevel;Water Level;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("waterlevel")).."]"..
|
||||
realterrain.esc(realterrain.get_setting("waterlevel")).."]"..
|
||||
"field[1,6;4,1;alpinelevel;Alpine Level;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("alpinelevel")).."]"..
|
||||
realterrain.esc(realterrain.get_setting("alpinelevel")).."]"..
|
||||
"field[1,7;4,1;yoffset;Vertical Offset;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("yoffset")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("yoffset")).."]" ..
|
||||
"field[1,8;4,1;xoffset;East Offset;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("xoffset")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("xoffset")).."]" ..
|
||||
"field[1,9;4,1;zoffset;North Offset;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("zoffset")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("zoffset")).."]" ..
|
||||
"label[6,1;Elevation File]"..
|
||||
"dropdown[6,1.5;4,1;filedem;"..f_images..";"..
|
||||
realterrain.get_image_id(images, realterrain.get_setting("filedem")) .."]" ..
|
||||
@ -466,103 +529,103 @@ function realterrain.show_biome_form(pname)
|
||||
|
||||
"label[0.2,0.6;01]"..
|
||||
"field[2,0.7;1,1;b01cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b01cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b01cut")).."]" ..
|
||||
"field[3,0.7;3,1;b01ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b01ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b01ground")).."]" ..
|
||||
"field[6,0.7;3,1;b01tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b01tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b01tree")).."]" ..
|
||||
"field[9,0.7;3,1;b01shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b01shrub")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b01shrub")).."]" ..
|
||||
|
||||
"label[0.2,1.6;02]"..
|
||||
"field[2,1.7;1,1;b02cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b02cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b02cut")).."]" ..
|
||||
"field[3,1.7;3,1;b02ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b02ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b02ground")).."]" ..
|
||||
"field[6,1.7;3,1;b02tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b02tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b02tree")).."]" ..
|
||||
"field[9,1.7;3,1;b02shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b02shrub")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b02shrub")).."]" ..
|
||||
|
||||
"label[0.2,2.6;03]"..
|
||||
"field[2,2.7;1,1;b03cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b03cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b03cut")).."]" ..
|
||||
"field[3,2.7;3,1;b03ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b03ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b03ground")).."]" ..
|
||||
"field[6,2.7;3,1;b03tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b03tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b03tree")).."]" ..
|
||||
"field[9,2.7;3,1;b03shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b03shrub")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b03shrub")).."]" ..
|
||||
|
||||
"label[0.2,3.6;04]"..
|
||||
"field[2,3.7;1,1;b04cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b04cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b04cut")).."]" ..
|
||||
"field[3,3.7;3,1;b04ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b04ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b04ground")).."]" ..
|
||||
"field[6,3.7;3,1;b04tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b04tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b04tree")).."]" ..
|
||||
"field[9,3.7;3,1;b04shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b04shrub")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b04shrub")).."]" ..
|
||||
|
||||
"label[0.2,4.6;05]"..
|
||||
"field[2,4.7;1,1;b05cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b05cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b05cut")).."]" ..
|
||||
"field[3,4.7;3,1;b05ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b05ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b05ground")).."]" ..
|
||||
"field[6,4.7;3,1;b05tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b05tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b05tree")).."]" ..
|
||||
"field[9,4.7;3,1;b05shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b05shrub")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b05shrub")).."]" ..
|
||||
|
||||
"label[0.2,5.6;06]"..
|
||||
"field[2,5.7;1,1;b06cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b06cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b06cut")).."]" ..
|
||||
"field[3,5.7;3,1;b06ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b06ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b06ground")).."]" ..
|
||||
"field[6,5.7;3,1;b06tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b06tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b06tree")).."]" ..
|
||||
"field[9,5.7;3,1;b06shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b06shrub")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b06shrub")).."]" ..
|
||||
|
||||
"label[0.2,6.6;07]"..
|
||||
"field[2,6.7;1,1;b07cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b07cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b07cut")).."]" ..
|
||||
"field[3,6.7;3,1;b07ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b07ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b07ground")).."]" ..
|
||||
"field[6,6.7;3,1;b07tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b07tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b07tree")).."]" ..
|
||||
"field[9,6.7;3,1;b07shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b07shrub")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b07shrub")).."]" ..
|
||||
|
||||
"label[0.2,7.6;08]"..
|
||||
"field[2,7.7;1,1;b08cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b08cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b08cut")).."]" ..
|
||||
"field[3,7.7;3,1;b08ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b08ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b08ground")).."]" ..
|
||||
"field[6,7.7;3,1;b08tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b08tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b08tree")).."]" ..
|
||||
"field[9,7.7;3,1;b08shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b08shrub")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b08shrub")).."]" ..
|
||||
|
||||
"label[0.2,8.6;09]"..
|
||||
"field[2,8.7;1,1;b09cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b09cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b09cut")).."]" ..
|
||||
"field[3,8.7;3,1;b09ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b09ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b09ground")).."]" ..
|
||||
"field[6,8.7;3,1;b09tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b09tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b09tree")).."]" ..
|
||||
"field[9,8.7;3,1;b09shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b09shrub")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b09shrub")).."]" ..
|
||||
|
||||
"label[0.2,9.6;10]"..
|
||||
"field[2,9.7;1,1;b10cut;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b10cut")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b10cut")).."]" ..
|
||||
"field[3,9.7;3,1;b10ground;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b10ground")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b10ground")).."]" ..
|
||||
"field[6,9.7;3,1;b10tree;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b10tree")).."]" ..
|
||||
realterrain.esc(realterrain.get_setting("b10tree")).."]" ..
|
||||
"field[9,9.7;3,1;b10shrub;;"..
|
||||
minetest.formspec_escape(realterrain.get_setting("b10shrub")).."]"
|
||||
realterrain.esc(realterrain.get_setting("b10shrub")).."]"
|
||||
|
||||
)
|
||||
return true
|
||||
@ -574,7 +637,7 @@ function realterrain.show_popup(pname, message)
|
||||
minetest.show_formspec(pname, "realterrain:popup",
|
||||
"size[10,8]" ..
|
||||
"button_exit[1,1;2,1;exit;Back]"..
|
||||
"label[1,3;"..minetest.formspec_escape(message).."]"
|
||||
"label[1,3;"..realterrain.esc(message).."]"
|
||||
)
|
||||
return true
|
||||
end
|
504
lunatic-python-1.0/LICENSE
Normal file
504
lunatic-python-1.0/LICENSE
Normal file
@ -0,0 +1,504 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
2
lunatic-python-1.0/MANIFEST.in
Normal file
2
lunatic-python-1.0/MANIFEST.in
Normal file
@ -0,0 +1,2 @@
|
||||
recursive-include src *.c *.h
|
||||
include MANIFEST.in python.lua LICENSE Makefile
|
25
lunatic-python-1.0/Makefile
Normal file
25
lunatic-python-1.0/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
#
|
||||
# Simple wrapper for setup.py script
|
||||
#
|
||||
|
||||
DESTDIR=/
|
||||
PYTHON=python
|
||||
|
||||
prefix=/usr
|
||||
bindir=$(prefix)/bin
|
||||
|
||||
all:
|
||||
$(PYTHON) setup.py build
|
||||
|
||||
install:
|
||||
$(PYTHON) setup.py install \
|
||||
--root=$(DESTDIR) \
|
||||
--prefix=$(prefix) \
|
||||
--install-scripts=$(bindir)
|
||||
|
||||
dist:
|
||||
$(PYTHON) setup.py sdist
|
||||
|
||||
rpm:
|
||||
$(PYTHON) setup.py bdist_rpm
|
||||
|
14
lunatic-python-1.0/PKG-INFO
Normal file
14
lunatic-python-1.0/PKG-INFO
Normal file
@ -0,0 +1,14 @@
|
||||
Metadata-Version: 1.0
|
||||
Name: lunatic-python
|
||||
Version: 1.0
|
||||
Summary: Two-way bridge between Python and Lua
|
||||
Home-page: http://labix.org/lunatic-python
|
||||
Author: Gustavo Niemeyer
|
||||
Author-email: gustavo@niemeyer.net
|
||||
License: LGPL
|
||||
Description: Lunatic Python is a two-way bridge between Python and Lua, allowing these
|
||||
languages to intercommunicate. Being two-way means that it allows Lua inside
|
||||
Python, Python inside Lua, Lua inside Python inside Lua, Python inside Lua
|
||||
inside Python, and so on.
|
||||
|
||||
Platform: UNKNOWN
|
23
lunatic-python-1.0/python.lua
Normal file
23
lunatic-python-1.0/python.lua
Normal file
@ -0,0 +1,23 @@
|
||||
local path = os.getenv("LUA_SOPATH")
|
||||
if path then
|
||||
func = loadlib(path.."/lua-python.so", "luaopen_python")
|
||||
if func then
|
||||
func()
|
||||
return
|
||||
end
|
||||
end
|
||||
local modmask = "/usr/lib/python%d.%d/site-packages/lua-python.so"
|
||||
local loaded = false
|
||||
for i = 10, 2, -1 do
|
||||
for j = 10, 2, -1 do
|
||||
func = loadlib(string.format(modmask, i, j), "luaopen_python")
|
||||
if func then
|
||||
loaded = true
|
||||
func()
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not loaded then
|
||||
error("unable to find python module")
|
||||
end
|
3
lunatic-python-1.0/setup.cfg
Normal file
3
lunatic-python-1.0/setup.cfg
Normal file
@ -0,0 +1,3 @@
|
||||
[bdist_rpm]
|
||||
doc_files = python.lua LICENSE
|
||||
use_bzip2 = 1
|
43
lunatic-python-1.0/setup.py
Executable file
43
lunatic-python-1.0/setup.py
Executable file
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python
|
||||
from distutils.core import setup, Extension
|
||||
from distutils.sysconfig import get_python_lib, get_python_version
|
||||
import os
|
||||
|
||||
if os.path.isfile("MANIFEST"):
|
||||
os.unlink("MANIFEST")
|
||||
|
||||
# You may have to change these
|
||||
PYLIBS = ["python"+get_python_version(), "pthread", "util"]
|
||||
PYLIBDIR = [get_python_lib(standard_lib=True)+"/config"]
|
||||
LUALIBS = ["lua", "lualib"]
|
||||
LUALIBDIR = []
|
||||
|
||||
setup(name="lunatic-python",
|
||||
version = "1.0",
|
||||
description = "Two-way bridge between Python and Lua",
|
||||
author = "Gustavo Niemeyer",
|
||||
author_email = "gustavo@niemeyer.net",
|
||||
url = "http://labix.org/lunatic-python",
|
||||
license = "LGPL",
|
||||
long_description =
|
||||
"""\
|
||||
Lunatic Python is a two-way bridge between Python and Lua, allowing these
|
||||
languages to intercommunicate. Being two-way means that it allows Lua inside
|
||||
Python, Python inside Lua, Lua inside Python inside Lua, Python inside Lua
|
||||
inside Python, and so on.
|
||||
""",
|
||||
ext_modules = [
|
||||
Extension("lua-python",
|
||||
["src/pythoninlua.c", "src/luainpython.c"],
|
||||
library_dirs=PYLIBDIR,
|
||||
libraries=PYLIBS,
|
||||
extra_compile_args=["-rdynamic"],
|
||||
extra_link_args=["-rdynamic"]),
|
||||
Extension("lua",
|
||||
["src/pythoninlua.c", "src/luainpython.c"],
|
||||
library_dirs=LUALIBDIR,
|
||||
libraries=LUALIBS,
|
||||
extra_compile_args=["-rdynamic"],
|
||||
extra_link_args=["-rdynamic"]),
|
||||
],
|
||||
)
|
500
lunatic-python-1.0/src/luainpython.c
Normal file
500
lunatic-python-1.0/src/luainpython.c
Normal file
@ -0,0 +1,500 @@
|
||||
/*
|
||||
|
||||
Lunatic Python
|
||||
--------------
|
||||
|
||||
Copyright (c) 2002-2005 Gustavo Niemeyer <gustavo@niemeyer.net>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
#include <Python.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
|
||||
#include "pythoninlua.h"
|
||||
#include "luainpython.h"
|
||||
|
||||
lua_State *LuaState = NULL;
|
||||
|
||||
static PyObject *LuaObject_New(int n);
|
||||
|
||||
PyObject *LuaConvert(lua_State *L, int n)
|
||||
{
|
||||
PyObject *ret = NULL;
|
||||
|
||||
switch (lua_type(L, n)) {
|
||||
|
||||
case LUA_TNIL:
|
||||
Py_INCREF(Py_None);
|
||||
ret = Py_None;
|
||||
break;
|
||||
|
||||
case LUA_TSTRING: {
|
||||
const char *s = lua_tostring(L, n);
|
||||
int len = lua_strlen(L, n);
|
||||
ret = PyString_FromStringAndSize(s, len);
|
||||
break;
|
||||
}
|
||||
|
||||
case LUA_TNUMBER: {
|
||||
lua_Number num = lua_tonumber(L, n);
|
||||
if (num != (long)num) {
|
||||
ret = PyFloat_FromDouble(
|
||||
(lua_Number)lua_tonumber(L, n));
|
||||
} else {
|
||||
ret = PyInt_FromLong((long)num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case LUA_TBOOLEAN:
|
||||
if (lua_toboolean(L, n)) {
|
||||
Py_INCREF(Py_True);
|
||||
ret = Py_True;
|
||||
} else {
|
||||
Py_INCREF(Py_False);
|
||||
ret = Py_False;
|
||||
}
|
||||
break;
|
||||
|
||||
case LUA_TUSERDATA: {
|
||||
py_object *obj = (py_object*)
|
||||
luaL_checkudata(L, n, POBJECT);
|
||||
|
||||
if (obj) {
|
||||
Py_INCREF(obj->o);
|
||||
ret = obj->o;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Otherwise go on and handle as custom. */
|
||||
}
|
||||
|
||||
default:
|
||||
ret = LuaObject_New(n);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *LuaCall(lua_State *L, PyObject *args)
|
||||
{
|
||||
PyObject *ret = NULL;
|
||||
PyObject *arg;
|
||||
int nargs, rc, i;
|
||||
|
||||
if (!PyTuple_Check(args)) {
|
||||
PyErr_SetString(PyExc_TypeError, "tuple expected");
|
||||
lua_settop(L, 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nargs = PyTuple_Size(args);
|
||||
for (i = 0; i != nargs; i++) {
|
||||
arg = PyTuple_GetItem(args, i);
|
||||
if (arg == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"failed to get tuple item #%d", i);
|
||||
lua_settop(L, 0);
|
||||
return NULL;
|
||||
}
|
||||
rc = py_convert(L, arg, 0);
|
||||
if (!rc) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"failed to convert argument #%d", i);
|
||||
lua_settop(L, 0);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (lua_pcall(L, nargs, LUA_MULTRET, 0) != 0) {
|
||||
PyErr_Format(PyExc_Exception,
|
||||
"error: %s", lua_tostring(L, -1));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nargs = lua_gettop(L);
|
||||
if (nargs == 1) {
|
||||
ret = LuaConvert(L, 1);
|
||||
if (!ret) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"failed to convert return");
|
||||
lua_settop(L, 0);
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
} else if (nargs > 1) {
|
||||
ret = PyTuple_New(nargs);
|
||||
if (!ret) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"failed to create return tuple");
|
||||
lua_settop(L, 0);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i != nargs; i++) {
|
||||
arg = LuaConvert(L, i+1);
|
||||
if (!arg) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"failed to convert return #%d", i);
|
||||
lua_settop(L, 0);
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
PyTuple_SetItem(ret, i, arg);
|
||||
}
|
||||
} else {
|
||||
Py_INCREF(Py_None);
|
||||
ret = Py_None;
|
||||
}
|
||||
|
||||
lua_settop(L, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define L LuaState
|
||||
|
||||
static PyObject *LuaObject_New(int n)
|
||||
{
|
||||
LuaObject *obj = PyObject_New(LuaObject, &LuaObject_Type);
|
||||
if (obj) {
|
||||
lua_pushvalue(L, n);
|
||||
obj->ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
obj->refiter = 0;
|
||||
}
|
||||
return (PyObject*) obj;
|
||||
}
|
||||
|
||||
static void LuaObject_dealloc(LuaObject *self)
|
||||
{
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, self->ref);
|
||||
if (self->refiter)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, self->refiter);
|
||||
self->ob_type->tp_free((PyObject *)self);
|
||||
}
|
||||
|
||||
static PyObject *LuaObject_getattr(PyObject *obj, PyObject *attr)
|
||||
{
|
||||
PyObject *ret = NULL;
|
||||
int rc;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((LuaObject*)obj)->ref);
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
PyErr_SetString(PyExc_RuntimeError, "lost reference");
|
||||
return NULL;
|
||||
}
|
||||
rc = py_convert(L, attr, 0);
|
||||
if (rc) {
|
||||
lua_gettable(L, -2);
|
||||
ret = LuaConvert(L, -1);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_ValueError, "can't convert attr/key");
|
||||
}
|
||||
lua_settop(L, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int LuaObject_setattr(PyObject *obj, PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = -1;
|
||||
int rc;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((LuaObject*)obj)->ref);
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
PyErr_SetString(PyExc_RuntimeError, "lost reference");
|
||||
return -1;
|
||||
}
|
||||
if (!lua_istable(L, -1)) {
|
||||
lua_pop(L, -1);
|
||||
PyErr_SetString(PyExc_TypeError, "Lua object is not a table");
|
||||
return -1;
|
||||
}
|
||||
rc = py_convert(L, attr, 0);
|
||||
if (rc) {
|
||||
rc = py_convert(L, value, 0);
|
||||
if (rc) {
|
||||
lua_settable(L, -3);
|
||||
ret = 0;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"can't convert value");
|
||||
}
|
||||
} else {
|
||||
PyErr_SetString(PyExc_ValueError, "can't convert key/attr");
|
||||
}
|
||||
lua_settop(L, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *LuaObject_str(PyObject *obj)
|
||||
{
|
||||
PyObject *ret = NULL;
|
||||
const char *s;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((LuaObject*)obj)->ref);
|
||||
if (luaL_callmeta(L, -1, "__tostring")) {
|
||||
s = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (s) ret = PyString_FromString(s);
|
||||
}
|
||||
if (!ret) {
|
||||
int type = lua_type(L, -1);
|
||||
switch (type) {
|
||||
case LUA_TTABLE:
|
||||
case LUA_TFUNCTION:
|
||||
ret = PyString_FromFormat("<Lua %s at %p>",
|
||||
lua_typename(L, type),
|
||||
lua_topointer(L, -1));
|
||||
break;
|
||||
|
||||
case LUA_TUSERDATA:
|
||||
case LUA_TLIGHTUSERDATA:
|
||||
ret = PyString_FromFormat("<Lua %s at %p>",
|
||||
lua_typename(L, type),
|
||||
lua_touserdata(L, -1));
|
||||
break;
|
||||
|
||||
case LUA_TTHREAD:
|
||||
ret = PyString_FromFormat("<Lua %s at %p>",
|
||||
lua_typename(L, type),
|
||||
(void*)lua_tothread(L, -1));
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = PyString_FromFormat("<Lua %s>",
|
||||
lua_typename(L, type));
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *LuaObject_call(PyObject *obj, PyObject *args)
|
||||
{
|
||||
lua_settop(L, 0);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((LuaObject*)obj)->ref);
|
||||
return LuaCall(L, args);
|
||||
}
|
||||
|
||||
static PyObject *LuaObject_iternext(LuaObject *obj)
|
||||
{
|
||||
PyObject *ret = NULL;
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((LuaObject*)obj)->ref);
|
||||
|
||||
if (obj->refiter == 0)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, obj->refiter);
|
||||
|
||||
if (lua_next(L, -2) != 0) {
|
||||
/* Remove value. */
|
||||
lua_pop(L, 1);
|
||||
ret = LuaConvert(L, -1);
|
||||
/* Save key for next iteration. */
|
||||
if (!obj->refiter)
|
||||
obj->refiter = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
else
|
||||
lua_rawseti(L, LUA_REGISTRYINDEX, obj->refiter);
|
||||
} else if (obj->refiter) {
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, obj->refiter);
|
||||
obj->refiter = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int LuaObject_length(LuaObject *obj)
|
||||
{
|
||||
int len;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((LuaObject*)obj)->ref);
|
||||
len = luaL_getn(L, -1);
|
||||
lua_settop(L, 0);
|
||||
return len;
|
||||
}
|
||||
|
||||
static PyObject *LuaObject_subscript(PyObject *obj, PyObject *key)
|
||||
{
|
||||
return LuaObject_getattr(obj, key);
|
||||
}
|
||||
|
||||
static int LuaObject_ass_subscript(PyObject *obj,
|
||||
PyObject *key, PyObject *value)
|
||||
{
|
||||
return LuaObject_setattr(obj, key, value);
|
||||
}
|
||||
|
||||
static PyMappingMethods LuaObject_as_mapping = {
|
||||
(inquiry)LuaObject_length, /*mp_length*/
|
||||
(binaryfunc)LuaObject_subscript,/*mp_subscript*/
|
||||
(objobjargproc)LuaObject_ass_subscript,/*mp_ass_subscript*/
|
||||
};
|
||||
|
||||
PyTypeObject LuaObject_Type = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"lua.custom", /*tp_name*/
|
||||
sizeof(LuaObject), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)LuaObject_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
LuaObject_str, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
&LuaObject_as_mapping, /*tp_as_mapping*/
|
||||
0, /*tp_hash*/
|
||||
(ternaryfunc)LuaObject_call, /*tp_call*/
|
||||
LuaObject_str, /*tp_str*/
|
||||
LuaObject_getattr, /*tp_getattro*/
|
||||
LuaObject_setattr, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
PyObject_SelfIter, /*tp_iter*/
|
||||
(iternextfunc)LuaObject_iternext, /*tp_iternext*/
|
||||
0, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
0, /*tp_getset*/
|
||||
0, /*tp_base*/
|
||||
0, /*tp_dict*/
|
||||
0, /*tp_descr_get*/
|
||||
0, /*tp_descr_set*/
|
||||
0, /*tp_dictoffset*/
|
||||
0, /*tp_init*/
|
||||
PyType_GenericAlloc, /*tp_alloc*/
|
||||
PyType_GenericNew, /*tp_new*/
|
||||
_PyObject_Del, /*tp_free*/
|
||||
0, /*tp_is_gc*/
|
||||
};
|
||||
|
||||
|
||||
PyObject *Lua_run(PyObject *args, int eval)
|
||||
{
|
||||
PyObject *ret;
|
||||
char *buf = NULL;
|
||||
char *s;
|
||||
int len;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#", &s, &len))
|
||||
return NULL;
|
||||
|
||||
if (eval) {
|
||||
buf = (char *) malloc(sizeof("return ")+len);
|
||||
strcpy(buf, "return ");
|
||||
strncat(buf, s, len);
|
||||
s = buf;
|
||||
len = sizeof("return ")-1+len;
|
||||
}
|
||||
|
||||
if (luaL_loadbuffer(L, s, len, "<python>") != 0) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"error loading code: %s",
|
||||
lua_tostring(L, -1));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
if (lua_pcall(L, 0, 1, 0) != 0) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"error executing code: %s",
|
||||
lua_tostring(L, -1));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = LuaConvert(L, -1);
|
||||
lua_settop(L, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
PyObject *Lua_execute(PyObject *self, PyObject *args)
|
||||
{
|
||||
return Lua_run(args, 0);
|
||||
}
|
||||
|
||||
PyObject *Lua_eval(PyObject *self, PyObject *args)
|
||||
{
|
||||
return Lua_run(args, 1);
|
||||
}
|
||||
|
||||
PyObject *Lua_globals(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *ret = NULL;
|
||||
lua_pushliteral(L, "_G");
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_isnil(L, -1)) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"lost globals reference");
|
||||
lua_pop(L, 1);
|
||||
return NULL;
|
||||
}
|
||||
ret = LuaConvert(L, -1);
|
||||
if (!ret)
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"failed to convert globals table");
|
||||
lua_settop(L, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *Lua_require(PyObject *self, PyObject *args)
|
||||
{
|
||||
lua_pushliteral(L, "require");
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
PyErr_SetString(PyExc_RuntimeError, "require is not defined");
|
||||
return NULL;
|
||||
}
|
||||
return LuaCall(L, args);
|
||||
}
|
||||
|
||||
static PyMethodDef lua_methods[] = {
|
||||
{"execute", Lua_execute, METH_VARARGS, NULL},
|
||||
{"eval", Lua_eval, METH_VARARGS, NULL},
|
||||
{"globals", Lua_globals, METH_NOARGS, NULL},
|
||||
{"require", Lua_require, METH_VARARGS, NULL},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
DL_EXPORT(void)
|
||||
initlua(void)
|
||||
{
|
||||
PyObject *m;
|
||||
m = Py_InitModule("lua", lua_methods);
|
||||
|
||||
if (!L) {
|
||||
L = lua_open();
|
||||
luaopen_base(L);
|
||||
luaopen_table(L);
|
||||
luaopen_io(L);
|
||||
luaopen_string(L);
|
||||
luaopen_debug(L);
|
||||
luaopen_loadlib(L);
|
||||
luaopen_python(L);
|
||||
lua_settop(L, 0);
|
||||
}
|
||||
}
|
42
lunatic-python-1.0/src/luainpython.h
Normal file
42
lunatic-python-1.0/src/luainpython.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
Lunatic Python
|
||||
--------------
|
||||
|
||||
Copyright (c) 2002-2005 Gustavo Niemeyer <gustavo@niemeyer.net>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
#ifndef LUAINPYTHON_H
|
||||
#define LUAINPYTHON_H
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
int ref;
|
||||
int refiter;
|
||||
} LuaObject;
|
||||
|
||||
PyAPI_DATA(PyTypeObject) LuaObject_Type;
|
||||
|
||||
#define LuaObject_Check(op) PyObject_TypeCheck(op, &LuaObject_Type)
|
||||
|
||||
PyObject *LuaConvert(lua_State *L, int n);
|
||||
|
||||
extern lua_State *LuaState;
|
||||
|
||||
DL_EXPORT(void) initlua(void);
|
||||
|
||||
#endif
|
611
lunatic-python-1.0/src/pythoninlua.c
Normal file
611
lunatic-python-1.0/src/pythoninlua.c
Normal file
@ -0,0 +1,611 @@
|
||||
/*
|
||||
|
||||
Lunatic Python
|
||||
--------------
|
||||
|
||||
Copyright (c) 2002-2005 Gustavo Niemeyer <gustavo@niemeyer.net>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
#include <Python.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
#include "pythoninlua.h"
|
||||
#include "luainpython.h"
|
||||
|
||||
static int py_asfunc_call(lua_State *L);
|
||||
|
||||
static int py_convert_custom(lua_State *L, PyObject *o, int asindx)
|
||||
{
|
||||
int ret = 0;
|
||||
py_object *obj = (py_object*) lua_newuserdata(L, sizeof(py_object));
|
||||
if (obj) {
|
||||
Py_INCREF(o);
|
||||
obj->o = o;
|
||||
obj->asindx = asindx;
|
||||
luaL_getmetatable(L, POBJECT);
|
||||
lua_setmetatable(L, -2);
|
||||
ret = 1;
|
||||
} else {
|
||||
luaL_error(L, "failed to allocate userdata object");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int py_convert(lua_State *L, PyObject *o, int withnone)
|
||||
{
|
||||
int ret = 0;
|
||||
if (o == Py_None) {
|
||||
if (withnone) {
|
||||
lua_pushliteral(L, "Py_None");
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
luaL_error(L, "lost none from registry");
|
||||
}
|
||||
} else {
|
||||
/* Not really needed, but this way we may check
|
||||
* for errors with ret == 0. */
|
||||
lua_pushnil(L);
|
||||
ret = 1;
|
||||
}
|
||||
} else if (o == Py_True) {
|
||||
lua_pushboolean(L, 1);
|
||||
} else if (o == Py_False) {
|
||||
lua_pushboolean(L, 0);
|
||||
} else if (PyString_Check(o)) {
|
||||
char *s;
|
||||
int len;
|
||||
PyString_AsStringAndSize(o, &s, &len);
|
||||
lua_pushlstring(L, s, len);
|
||||
ret = 1;
|
||||
} else if (PyInt_Check(o) || PyFloat_Check(o)) {
|
||||
lua_pushnumber(L, (lua_Number)PyInt_AsLong(o));
|
||||
ret = 1;
|
||||
} else if (LuaObject_Check(o)) {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ((LuaObject*)o)->ref);
|
||||
ret = 1;
|
||||
} else {
|
||||
int asindx = 0;
|
||||
if (PyDict_Check(o) || PyList_Check(o) || PyTuple_Check(o))
|
||||
asindx = 1;
|
||||
ret = py_convert_custom(L, o, asindx);
|
||||
if (ret && !asindx &&
|
||||
(PyFunction_Check(o) || PyCFunction_Check(o)))
|
||||
lua_pushcclosure(L, py_asfunc_call, 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int py_object_call(lua_State *L)
|
||||
{
|
||||
py_object *obj = (py_object*) luaL_checkudata(L, 1, POBJECT);
|
||||
PyObject *args;
|
||||
PyObject *value;
|
||||
int nargs = lua_gettop(L)-1;
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
if (!obj) {
|
||||
luaL_argerror(L, 1, "not a python object");
|
||||
return 0;
|
||||
}
|
||||
if (!PyCallable_Check(obj->o)) {
|
||||
luaL_error(L, "object is not callable");
|
||||
return 0;
|
||||
}
|
||||
|
||||
args = PyTuple_New(nargs);
|
||||
if (!args) {
|
||||
PyErr_Print();
|
||||
luaL_error(L, "failed to create arguments tuple");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i != nargs; i++) {
|
||||
PyObject *arg = LuaConvert(L, i+2);
|
||||
if (!arg) {
|
||||
luaL_error(L, "failed to convert argument #%d", i+1);
|
||||
Py_DECREF(args);
|
||||
return 0;
|
||||
}
|
||||
PyTuple_SetItem(args, i, arg);
|
||||
}
|
||||
|
||||
value = PyObject_CallObject(obj->o, args);
|
||||
if (value) {
|
||||
ret = py_convert(L, value, 0);
|
||||
Py_DECREF(value);
|
||||
} else {
|
||||
PyErr_Print();
|
||||
luaL_error(L, "error calling python function");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int _p_object_newindex_set(lua_State *L, py_object *obj,
|
||||
int keyn, int valuen)
|
||||
{
|
||||
PyObject *value;
|
||||
PyObject *key = LuaConvert(L, keyn);
|
||||
|
||||
if (!key) {
|
||||
luaL_argerror(L, 1, "failed to convert key");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!lua_isnil(L, valuen)) {
|
||||
value = LuaConvert(L, valuen);
|
||||
if (!value) {
|
||||
Py_DECREF(key);
|
||||
luaL_argerror(L, 1, "failed to convert value");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PyObject_SetItem(obj->o, key, value) == -1) {
|
||||
PyErr_Print();
|
||||
luaL_error(L, "failed to set item");
|
||||
}
|
||||
|
||||
Py_DECREF(value);
|
||||
} else {
|
||||
if (PyObject_DelItem(obj->o, key) == -1) {
|
||||
PyErr_Print();
|
||||
luaL_error(L, "failed to delete item");
|
||||
}
|
||||
}
|
||||
|
||||
Py_DECREF(key);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int py_object_newindex_set(lua_State *L)
|
||||
{
|
||||
py_object *obj = (py_object*) luaL_checkudata(L, lua_upvalueindex(1),
|
||||
POBJECT);
|
||||
if (lua_gettop(L) != 2) {
|
||||
luaL_error(L, "invalid arguments");
|
||||
return 0;
|
||||
}
|
||||
return _p_object_newindex_set(L, obj, 1, 2);
|
||||
}
|
||||
|
||||
static int py_object_newindex(lua_State *L)
|
||||
{
|
||||
py_object *obj = (py_object*) luaL_checkudata(L, 1, POBJECT);
|
||||
const char *attr;
|
||||
PyObject *value;
|
||||
|
||||
if (!obj) {
|
||||
luaL_argerror(L, 1, "not a python object");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (obj->asindx)
|
||||
return _p_object_newindex_set(L, obj, 2, 3);
|
||||
|
||||
attr = luaL_checkstring(L, 2);
|
||||
if (!attr) {
|
||||
luaL_argerror(L, 2, "string needed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
value = LuaConvert(L, 3);
|
||||
if (!value) {
|
||||
luaL_argerror(L, 1, "failed to convert value");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PyObject_SetAttrString(obj->o, (char*)attr, value) == -1) {
|
||||
Py_DECREF(value);
|
||||
PyErr_Print();
|
||||
luaL_error(L, "failed to set value");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Py_DECREF(value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _p_object_index_get(lua_State *L, py_object *obj, int keyn)
|
||||
{
|
||||
PyObject *key = LuaConvert(L, keyn);
|
||||
PyObject *item;
|
||||
int ret = 0;
|
||||
|
||||
if (!key) {
|
||||
luaL_argerror(L, 1, "failed to convert key");
|
||||
return 0;
|
||||
}
|
||||
|
||||
item = PyObject_GetItem(obj->o, key);
|
||||
|
||||
Py_DECREF(key);
|
||||
|
||||
if (item) {
|
||||
ret = py_convert(L, item, 0);
|
||||
Py_DECREF(item);
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
if (lua_gettop(L) > keyn) {
|
||||
lua_pushvalue(L, keyn+1);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int py_object_index_get(lua_State *L)
|
||||
{
|
||||
py_object *obj = (py_object*) luaL_checkudata(L, lua_upvalueindex(1),
|
||||
POBJECT);
|
||||
int top = lua_gettop(L);
|
||||
if (top < 1 || top > 2) {
|
||||
luaL_error(L, "invalid arguments");
|
||||
return 0;
|
||||
}
|
||||
return _p_object_index_get(L, obj, 1);
|
||||
}
|
||||
|
||||
static int py_object_index(lua_State *L)
|
||||
{
|
||||
py_object *obj = (py_object*) luaL_checkudata(L, 1, POBJECT);
|
||||
const char *attr;
|
||||
PyObject *value;
|
||||
int ret = 0;
|
||||
|
||||
if (!obj) {
|
||||
luaL_argerror(L, 1, "not a python object");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (obj->asindx)
|
||||
return _p_object_index_get(L, obj, 2);
|
||||
|
||||
attr = luaL_checkstring(L, 2);
|
||||
if (!attr) {
|
||||
luaL_argerror(L, 2, "string needed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (attr[0] == '_' && strcmp(attr, "__get") == 0) {
|
||||
lua_pushvalue(L, 1);
|
||||
lua_pushcclosure(L, py_object_index_get, 1);
|
||||
return 1;
|
||||
} else if (attr[0] == '_' && strcmp(attr, "__set") == 0) {
|
||||
lua_pushvalue(L, 1);
|
||||
lua_pushcclosure(L, py_object_newindex_set, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
value = PyObject_GetAttrString(obj->o, (char*)attr);
|
||||
if (value) {
|
||||
ret = py_convert(L, value, 0);
|
||||
Py_DECREF(value);
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
luaL_error(L, "unknown attribute in python object");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int py_object_gc(lua_State *L)
|
||||
{
|
||||
py_object *obj = (py_object*) luaL_checkudata(L, 1, POBJECT);
|
||||
if (obj) {
|
||||
Py_DECREF(obj->o);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int py_object_tostring(lua_State *L)
|
||||
{
|
||||
py_object *obj = (py_object*) luaL_checkudata(L, 1, POBJECT);
|
||||
if (obj) {
|
||||
PyObject *repr = PyObject_Str(obj->o);
|
||||
if (!repr) {
|
||||
char buf[256];
|
||||
snprintf(buf, 256, "python object: %p", obj->o);
|
||||
lua_pushstring(L, buf);
|
||||
PyErr_Clear();
|
||||
} else {
|
||||
char *s;
|
||||
int len;
|
||||
PyString_AsStringAndSize(repr, &s, &len);
|
||||
lua_pushlstring(L, s, len);
|
||||
Py_DECREF(repr);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_reg py_object_lib[] = {
|
||||
{"__call", py_object_call},
|
||||
{"__index", py_object_index},
|
||||
{"__newindex", py_object_newindex},
|
||||
{"__gc", py_object_gc},
|
||||
{"__tostring", py_object_tostring},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static int py_run(lua_State *L, int eval)
|
||||
{
|
||||
const char *s;
|
||||
char *buffer = NULL;
|
||||
PyObject *m, *d, *o;
|
||||
int ret = 0;
|
||||
int len;
|
||||
|
||||
s = luaL_checkstring(L, 1);
|
||||
if (!s)
|
||||
return 0;
|
||||
|
||||
if (!eval) {
|
||||
len = strlen(s)+1;
|
||||
buffer = (char *) malloc(len+1);
|
||||
if (!buffer) {
|
||||
luaL_error(L, "Failed allocating buffer for execution");
|
||||
return 0;
|
||||
}
|
||||
strcpy(buffer, s);
|
||||
buffer[len-1] = '\n';
|
||||
buffer[len] = '\0';
|
||||
s = buffer;
|
||||
}
|
||||
|
||||
m = PyImport_AddModule("__main__");
|
||||
if (!m) {
|
||||
free(buffer);
|
||||
luaL_error(L, "Can't get __main__ module");
|
||||
return 0;
|
||||
}
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
o = PyRun_StringFlags(s, eval ? Py_eval_input : Py_single_input,
|
||||
d, d, NULL);
|
||||
|
||||
free(buffer);
|
||||
|
||||
if (!o) {
|
||||
PyErr_Print();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (py_convert(L, o, 0))
|
||||
ret = 1;
|
||||
|
||||
Py_DECREF(o);
|
||||
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int py_execute(lua_State *L)
|
||||
{
|
||||
return py_run(L, 0);
|
||||
}
|
||||
|
||||
static int py_eval(lua_State *L)
|
||||
{
|
||||
return py_run(L, 1);
|
||||
}
|
||||
|
||||
static int py_asindx(lua_State *L)
|
||||
{
|
||||
py_object *obj = (py_object*) luaL_checkudata(L, 1, POBJECT);
|
||||
if (obj)
|
||||
return py_convert_custom(L, obj->o, 1);
|
||||
else
|
||||
luaL_argerror(L, 1, "not a python object");
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int py_asattr(lua_State *L)
|
||||
{
|
||||
py_object *obj = (py_object*) luaL_checkudata(L, 1, POBJECT);
|
||||
if (obj)
|
||||
return py_convert_custom(L, obj->o, 0);
|
||||
else
|
||||
luaL_argerror(L, 1, "not a python object");
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int py_asfunc_call(lua_State *L)
|
||||
{
|
||||
lua_pushvalue(L, lua_upvalueindex(1));
|
||||
lua_insert(L, 1);
|
||||
return py_object_call(L);
|
||||
}
|
||||
|
||||
static int py_asfunc(lua_State *L)
|
||||
{
|
||||
int ret = 0;
|
||||
if (luaL_checkudata(L, 1, POBJECT)) {
|
||||
lua_pushcclosure(L, py_asfunc_call, 1);
|
||||
ret = 1;
|
||||
} else {
|
||||
luaL_argerror(L, 1, "not a python object");
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
static int py_globals(lua_State *L)
|
||||
{
|
||||
PyObject *globals;
|
||||
|
||||
if (lua_gettop(L) != 0) {
|
||||
luaL_error(L, "invalid arguments");
|
||||
return 0;
|
||||
}
|
||||
|
||||
globals = PyEval_GetGlobals();
|
||||
if (!globals) {
|
||||
PyObject *module = PyImport_AddModule("__main__");
|
||||
if (!module) {
|
||||
luaL_error(L, "Can't get __main__ module");
|
||||
return 0;
|
||||
}
|
||||
globals = PyModule_GetDict(module);
|
||||
}
|
||||
|
||||
if (!globals) {
|
||||
PyErr_Print();
|
||||
luaL_error(L, "can't get globals");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return py_convert_custom(L, globals, 1);
|
||||
}
|
||||
|
||||
static int py_locals(lua_State *L)
|
||||
{
|
||||
PyObject *locals;
|
||||
|
||||
if (lua_gettop(L) != 0) {
|
||||
luaL_error(L, "invalid arguments");
|
||||
return 0;
|
||||
}
|
||||
|
||||
locals = PyEval_GetLocals();
|
||||
if (!locals)
|
||||
return py_globals(L);
|
||||
|
||||
return py_convert_custom(L, locals, 1);
|
||||
}
|
||||
|
||||
static int py_builtins(lua_State *L)
|
||||
{
|
||||
PyObject *builtins;
|
||||
|
||||
if (lua_gettop(L) != 0) {
|
||||
luaL_error(L, "invalid arguments");
|
||||
return 0;
|
||||
}
|
||||
|
||||
builtins = PyEval_GetBuiltins();
|
||||
if (!builtins) {
|
||||
PyErr_Print();
|
||||
luaL_error(L, "failed to get builtins");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return py_convert_custom(L, builtins, 1);
|
||||
}
|
||||
|
||||
static int py_import(lua_State *L)
|
||||
{
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
PyObject *module;
|
||||
int ret;
|
||||
|
||||
if (!name) {
|
||||
luaL_argerror(L, 1, "module name expected");
|
||||
return 0;
|
||||
}
|
||||
|
||||
module = PyImport_ImportModule((char*)name);
|
||||
|
||||
if (!module) {
|
||||
PyErr_Print();
|
||||
luaL_error(L, "failed importing '%s'", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = py_convert_custom(L, module, 0);
|
||||
Py_DECREF(module);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const luaL_reg py_lib[] = {
|
||||
{"execute", py_execute},
|
||||
{"eval", py_eval},
|
||||
{"asindx", py_asindx},
|
||||
{"asattr", py_asattr},
|
||||
{"asfunc", py_asfunc},
|
||||
{"locals", py_locals},
|
||||
{"globals", py_globals},
|
||||
{"builtins", py_builtins},
|
||||
{"import", py_import},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
LUA_API int luaopen_python(lua_State *L)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Register module */
|
||||
luaL_openlib(L, "python", py_lib, 0);
|
||||
|
||||
/* Register python object metatable */
|
||||
luaL_newmetatable(L, POBJECT);
|
||||
luaL_openlib(L, NULL, py_object_lib, 0);
|
||||
lua_pop(L, 1);
|
||||
|
||||
/* Initialize Lua state in Python territory */
|
||||
if (!LuaState) LuaState = L;
|
||||
|
||||
/* Initialize Python interpreter */
|
||||
if (!Py_IsInitialized()) {
|
||||
PyObject *luam, *mainm, *maind;
|
||||
char *argv[] = {"<lua>", 0};
|
||||
Py_SetProgramName("<lua>");
|
||||
Py_Initialize();
|
||||
PySys_SetArgv(1, argv);
|
||||
initlua();
|
||||
/* Import 'lua' automatically. */
|
||||
luam = PyImport_ImportModule("lua");
|
||||
if (!luam) {
|
||||
luaL_error(L, "Can't import lua module");
|
||||
} else {
|
||||
mainm = PyImport_AddModule("__main__");
|
||||
if (!mainm) {
|
||||
luaL_error(L, "Can't get __main__ module");
|
||||
} else {
|
||||
maind = PyModule_GetDict(mainm);
|
||||
PyDict_SetItemString(maind, "lua", luam);
|
||||
Py_DECREF(luam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Register 'none' */
|
||||
lua_pushliteral(L, "Py_None");
|
||||
rc = py_convert_custom(L, Py_None, 0);
|
||||
if (rc) {
|
||||
lua_pushliteral(L, "none");
|
||||
lua_pushvalue(L, -2);
|
||||
lua_rawset(L, -5); /* python.none */
|
||||
lua_rawset(L, LUA_REGISTRYINDEX); /* registry.Py_None */
|
||||
} else {
|
||||
lua_pop(L, 1);
|
||||
luaL_error(L, "failed to convert none object");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
37
lunatic-python-1.0/src/pythoninlua.h
Normal file
37
lunatic-python-1.0/src/pythoninlua.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
|
||||
Lunatic Python
|
||||
--------------
|
||||
|
||||
Copyright (c) 2002-2005 Gustavo Niemeyer <gustavo@niemeyer.net>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
#ifndef PYTHONINLUA_H
|
||||
#define PYTHONINLUA_H
|
||||
|
||||
#define POBJECT "POBJECT"
|
||||
|
||||
int py_convert(lua_State *L, PyObject *o, int withnone);
|
||||
|
||||
typedef struct {
|
||||
PyObject *o;
|
||||
int asindx;
|
||||
} py_object;
|
||||
|
||||
LUA_API int luaopen_python(lua_State *L);
|
||||
|
||||
#endif
|
BIN
schems/cactus.mts
Normal file
BIN
schems/cactus.mts
Normal file
Binary file not shown.
BIN
schems/jungletree.mts
Normal file
BIN
schems/jungletree.mts
Normal file
Binary file not shown.
BIN
schems/snowtree.mts
Normal file
BIN
schems/snowtree.mts
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user