Commit e2fd560d authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Fix #45 support for com objects (update with com.lua from @prabirshrestha)

parent 7e8c165a
--require 'luanet'
require 'CLRPackage'
import 'System' import 'System'
import 'System.Reflection' import 'System.Reflection'
local get_flags = luanet.enum(BindingFlags,'GetProperty,IgnoreCase,Public') local get_flags = luanet.enum(BindingFlags,'GetProperty,IgnoreCase,Public')
...@@ -36,19 +34,12 @@ function com_wrapper(obj) ...@@ -36,19 +34,12 @@ function com_wrapper(obj)
local T = obj:GetType() local T = obj:GetType()
return setmetatable({},{ return setmetatable({},{
__index = function(self,key) __index = function(self,key)
local ok,res = pcall(T.InvokeMember,T,key,get_flags,nil,obj,empty) local ok,res = pcall(T.InvokeMember, T, key, get_flags, nil, obj, empty)
if not ok then if ok then
res = tostring(res) return maybe_wrap(res)
if res:match 'Member not found' then else
return caller(obj,key) --local c = return caller(obj, key)
--~ rawset(self,key,c) end
--~ return c
else
error("cannot find "..key,2)
end
else
return maybe_wrap(res)
end
end; end;
__newindex = function(self,key,value) __newindex = function(self,key,value)
T:InvokeMember(key,put_flags,nil,A{value}) T:InvokeMember(key,put_flags,nil,A{value})
...@@ -66,4 +57,4 @@ end ...@@ -66,4 +57,4 @@ end
com.wrap = maybe_wrap com.wrap = maybe_wrap
return com return com
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment