Merge Lua changes - branch 'class_p1' of github.com:v-for-vandal/swig into v-for-vandal-class_p1

* 'class_p1' of github.com:v-for-vandal/swig:
  Fixing registerClass. No more wrap: unnecessary attributes
  Fixed registerMethod to work like registerVariable
  Switched to Swig_name_* functions
  Return MIN_OPT_LEVEL for elua
  add nspace_extend test case
  updated documentation following comd options renaming
  Options in alphabetical order
  Members renaming
  target_name -> lua_name
  Fixing cmd options, again
  Fixing segfault
  Removed class_parent_nspace
  Fixes to module options
  Rename methods to make it clear what 'symbols table' they operate on.
  Small documenation fixes
  Updating Lua documentation
  Eliminating namespaces_hash and using symbols table instead
  Attempt to catch unreproducable bug from Travis CI build
  Small bugfixes
  Bugfixes for eLua. eLua emulation mode
  Add compatibility option for old-style inheritance
  Add support for C-style enums in C mode. And tests.
  Style fixes. Comments fixes. Fixing cmd options. etc
  Some fixes for elua
  Attempt to fix unreproducable bug (from Travis CI build)
  Fixes for examples. Wrapped keywords into guardian in keyword_rename test
  Remove some typos
  Remove some obsolete code
  Manually beautifying luarun.swg
  Code beautifier
  Valuewrapper test
  Removing obsolete debug code
  Bugfixes
  A few bugfixes
  Some class bases iteration improvements
  Fixes for elua
  Bugfixes
  Bugfixes. CMD args handling. Code cleanup
  Bugfixes
  Preparations before pull request - part 1
  More changes. Mostly to the would-be class library
  Fixing issuse with v2-compatible static function names
  Add pointer guard
  Add runtime test
  Bugfixes
  nspace.i example is working
  Initial implementation - everything compiles but might not work
This commit is contained in:
William S Fulton 2014-02-27 20:04:08 +00:00
commit 1be97ed26c
21 changed files with 2692 additions and 953 deletions

View file

@ -19,4 +19,12 @@ assert(enums.globalinstance3==30)
assert(enums.AnonEnum1==0)
assert(enums.AnonEnum2==100)
-- In C enums from struct are exported without prefixing with struct name
-- In C++ they are prefixed.
-- We are emulating xor :)
assert(enums.BAR1 ~= enums.Foo_BAR1) -- It is either C style, or C++ style, but not both
assert((enums.BAR1 ~= nil ) or (enums.Foo_BAR1 ~= nil))
assert(enums.Phoo ~= enums.iFoo_Phoo)
assert((enums.Phoo == 50) or (enums.iFoo_Phoo == 50))
-- no point in checking fns, C will allow any value

View file

@ -14,4 +14,5 @@ assert(g.test3 == 37)
g.test3 = 42
assert(g.test3 == 42)
assert(g.NEGATE ~= nil)
assert(g.do_unary(5, g.NEGATE) == -5)

View file

@ -1,8 +1,6 @@
require("import") -- the import fn
import("li_carrays") -- import code
-- moving to global
for k,v in pairs(li_carrays) do _G[k]=v end
lc = li_carrays
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
@ -10,22 +8,22 @@ if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
-- Testing for %array_functions(int,intArray)
ary = new_intArray(2)
intArray_setitem(ary, 0, 0)
intArray_setitem(ary, 1, 1)
assert(intArray_getitem(ary, 0)==0)
assert(intArray_getitem(ary, 1)==1)
delete_intArray(ary)
ary = lc.new_intArray(2)
lc.intArray_setitem(ary, 0, 0)
lc.intArray_setitem(ary, 1, 1)
assert(lc.intArray_getitem(ary, 0)==0)
assert(lc.intArray_getitem(ary, 1)==1)
lc.delete_intArray(ary)
-- Testing for %array_class(double, doubleArray)
d = doubleArray(10)
d = lc.doubleArray(10)
d[0] = 7
d[5] = d[0] + 3
assert(d[5] + d[0] == 17)
--print(d[5] + d[0])
ptr = d:cast() -- to ptr
d2 = doubleArray_frompointer(ptr) -- and back to array
d2 = lc.doubleArray_frompointer(ptr) -- and back to array
assert(d2[5] + d2[0] == 17)
--print(d2[5] + d2[0])

View file

@ -1,43 +1,46 @@
--Example using pointers to member functions
require("import") -- the import fn
import("member_pointer") -- import code
mp = member_pointer
for k,v in pairs(member_pointer) do _G[k]=v end
-- catching undefined variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
function check(what, expected, actual)
assert(expected == actual,"Failed: "..what.." Expected: "..expected.." Actual: "..actual)
end
-- Get the pointers
area_pt = areapt()
perim_pt = perimeterpt()
area_pt = mp.areapt()
perim_pt = mp.perimeterpt()
-- Create some objects
s = Square(10)
s = mp.Square(10)
-- Do some calculations
check ("Square area ", 100.0, do_op(s,area_pt))
check ("Square perim", 40.0, do_op(s,perim_pt))
check ("Square area ", 100.0, mp.do_op(s,area_pt))
check ("Square perim", 40.0, mp.do_op(s,perim_pt))
-- Try the variables
-- these have to still be part of the 'member_pointer' table
memberPtr = member_pointer.areavar
memberPtr = member_pointer.perimetervar
memberPtr = mp.areavar
memberPtr = mp.perimetervar
check ("Square area ", 100.0, do_op(s,member_pointer.areavar))
check ("Square perim", 40.0, do_op(s,member_pointer.perimetervar))
check ("Square area ", 100.0, mp.do_op(s,mp.areavar))
check ("Square perim", 40.0, mp.do_op(s,mp.perimetervar))
-- Modify one of the variables
member_pointer.areavar = perim_pt
mp.areavar = perim_pt
check ("Square perimeter", 40.0, do_op(s,member_pointer.areavar))
check ("Square perimeter", 40.0, mp.do_op(s,mp.areavar))
-- Try the constants
memberPtr = AREAPT
memberPtr = PERIMPT
memberPtr = NULLPT
memberPtr = mp.AREAPT
memberPtr = mp.PERIMPT
memberPtr = mp.NULLPT
check ("Square area ", 100.0, do_op(s,AREAPT))
check ("Square perim", 40.0, do_op(s,PERIMPT))
check ("Square area ", 100.0, mp.do_op(s,mp.AREAPT))
check ("Square perim", 40.0, mp.do_op(s,mp.PERIMPT))

View file

@ -1,8 +1,8 @@
require("import") -- the import fn
import("newobject1") -- import code
foo1 = newobject1.Foo_makeFoo() -- lua doesnt yet support static fns properly
assert(newobject1.Foo_fooCount() == 1) -- lua doesnt yet support static fns properly
foo1 = newobject1.Foo_makeFoo()
assert(newobject1.Foo_fooCount() == 1)
foo2 = foo1:makeMore()
assert(newobject1.Foo_fooCount() == 2)

View file

@ -0,0 +1,39 @@
require("import") -- the import fn
import("nspace_extend") -- import lib
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
ne = nspace_extend
-- Inner1
-- Constructors
in1_clr1 = ne.Outer.Inner1.Color()
in1_clr2 = ne.Outer.Inner1.Color.create()
in1_clr3 = ne.Outer.Inner1.Color(in1_clr2)
-- methods
in1_clr1:colorInstanceMethod(1.0)
ne.Outer.Inner1.Color.colorStaticMethod(2.0)
-- Inner2
-- Constructors
in2_clr1 = ne.Outer.Inner2.Color()
in2_clr2 = ne.Outer.Inner2.Color.create()
in2_clr3 = ne.Outer.Inner2.Color(in2_clr2)
assert(pcall(ne.Outer.Inner2.Color, in1_clr1) == false)
-- methods
in2_clr1:colorInstanceMethod(1.0)
ne.Outer.Inner2.Color.colorStaticMethod(2.0)
in2_clr3:colors(in1_clr1, in1_clr2, in2_clr2, in2_clr2, in2_clr3)
assert(pcall(in2_clr3.colors, in2_clr3,
in2_clr1, in2_clr2, in1_clr2, in2_clr2, in2_clr3) == false)

View file

@ -0,0 +1,67 @@
require("import") -- the import fn
import("nspace") -- import lib
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
ns = nspace
-- Inheritance
blue1 = ns.Outer.Inner3.Blue()
-- blue1:blueInstanceMethod()
blue1:colorInstanceMethod(60.0)
blue1.instanceMemberVariable = 4
assert( blue1.instanceMemberVariable == 4 )
-- Constructors
color1 = ns.Outer.Inner1.Color()
color2 = ns.Outer.Inner1.Color.create()
color = ns.Outer.Inner1.Color(color1)
color3 = ns.Outer.Inner2.Color.create()
color4 = ns.Outer.Inner2.Color.create()
color5 = ns.Outer.Inner2.Color.create()
mwp2 = ns.Outer.MyWorldPart2()
gc = ns.GlobalClass()
nnsp = ns.NoNSpacePlease()
-- Class methods
color:colorInstanceMethod(20.0)
ns.Outer.Inner1.Color.colorStaticMethod(30.0)
color3:colorInstanceMethod(40.0)
ns.Outer.Inner2.Color.colorStaticMethod(50.0)
color3:colors(color1, color2, color3, color4, color5)
gc:gmethod()
-- Class variables
color.instanceMemberVariable = 5
color1.instanceMemberVariable = 7
assert( color.instanceMemberVariable == 5 )
assert( color1.instanceMemberVariable == 7 )
assert(ns.Outer.Inner1.Color.staticMemberVariable == 0 )
assert(ns.Outer.Inner2.Color.staticMemberVariable == 0 )
ns.Outer.Inner1.Color.staticMemberVariable = 9
ns.Outer.Inner2.Color.staticMemberVariable = 11
assert(ns.Outer.Inner1.Color.staticMemberVariable == 9)
assert(ns.Outer.Inner2.Color.staticMemberVariable == 11)
-- Class constants
assert( ns.Outer.Inner1.Color.Specular == 0x20 )
assert( ns.Outer.Inner2.Color.Specular == 0x40 )
assert( ns.Outer.Inner1.Color.staticConstMemberVariable == 222 )
assert( ns.Outer.Inner2.Color.staticConstMemberVariable == 333 )
assert( ns.Outer.Inner1.Color.staticConstEnumMemberVariable ~= ns.Outer.Inner2.Color.staticConstEnumMemberVariable )
-- Aggregation
sc = ns.Outer.SomeClass()
assert( sc:GetInner1ColorChannel() ~= sc:GetInner2Channel() )
assert( sc:GetInner1Channel() ~= sc:GetInner2Channel() )

View file

@ -3,6 +3,7 @@ import("template_default_arg") -- import code
--for k,v in pairs(template_default_arg) do _G[k]=v end -- move to global
helloInt = template_default_arg.Hello_int()
assert(template_default_arg.Hello_int_hi ~= nil)
helloInt:foo(template_default_arg.Hello_int_hi)
x = template_default_arg.X_int()

View file

@ -0,0 +1,17 @@
require("import") -- the import fn
import("valuewrapper") -- import code
v=valuewrapper -- renaming import
-- catch "undefined" global variables
local env = _ENV -- Lua 5.2
if not env then env = getfenv () end -- Lua 5.1
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
assert(v.Xi ~= nil)
assert(v.YXi ~= nil)
x1 = v.Xi(5)
y1 =v.YXi()
assert(y1:spam(x1) == 0)
assert(y1:spam() == 0)