diff options
author | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2015-05-28 15:54:35 +0100 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2015-05-28 15:54:35 +0100 |
commit | 3aabb41d1d05eb05fbefa9ab76f2bdbc6b322ffe (patch) | |
tree | 03836526413ea7be4cacb1eb532998ac1b034adc | |
parent | 59ecddb55e7d2feb4550f5a39e26947ab3613e4c (diff) |
elua: make eo bindings work with the new generated format
-rw-r--r-- | src/bindings/luajit/eo.lua | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/src/bindings/luajit/eo.lua b/src/bindings/luajit/eo.lua index 2944e5e579..6f7bd160ce 100644 --- a/src/bindings/luajit/eo.lua +++ b/src/bindings/luajit/eo.lua | |||
@@ -344,14 +344,18 @@ end | |||
344 | 344 | ||
345 | local prop_proxy_meta = { | 345 | local prop_proxy_meta = { |
346 | __index = function(self, key) | 346 | __index = function(self, key) |
347 | if self.nkeys > 1 and type(key) == "table" then | 347 | local ngkeys = self.ngkeys |
348 | if self.nvals > 1 then | 348 | if ngkeys <= 0 then |
349 | error("property '" .. self.key .. "' has no getter keys", 2) | ||
350 | end | ||
351 | if ngkeys > 1 and type(key) == "table" then | ||
352 | if self.ngvals > 1 then | ||
349 | return { self(unpack(key)) } | 353 | return { self(unpack(key)) } |
350 | else | 354 | else |
351 | return self(unpack(key)) | 355 | return self(unpack(key)) |
352 | end | 356 | end |
353 | else | 357 | else |
354 | if self.nvals > 1 then | 358 | if self.ngvals > 1 then |
355 | return { self(key) } | 359 | return { self(key) } |
356 | else | 360 | else |
357 | return self(key) | 361 | return self(key) |
@@ -360,8 +364,11 @@ local prop_proxy_meta = { | |||
360 | end, | 364 | end, |
361 | 365 | ||
362 | __newindex = function(self, key, val) | 366 | __newindex = function(self, key, val) |
363 | local nkeys = self.nkeys | 367 | local nskeys = self.nskeys |
364 | if nkeys > 1 then | 368 | if nskeys <= 0 then |
369 | error("property '" .. self.key .. "' has no setter keys", 2) | ||
370 | end | ||
371 | if nskeys > 1 then | ||
365 | -- ultra slow path, q66 failed optimizing this | 372 | -- ultra slow path, q66 failed optimizing this |
366 | -- if you ever get to touch this, increment this | 373 | -- if you ever get to touch this, increment this |
367 | -- counter to let others know you failed too. | 374 | -- counter to let others know you failed too. |
@@ -375,14 +382,14 @@ local prop_proxy_meta = { | |||
375 | else | 382 | else |
376 | atbl = { key } | 383 | atbl = { key } |
377 | end | 384 | end |
378 | if self.nvals > 1 and type(val) == "table" then | 385 | if self.nsvals > 1 and type(val) == "table" then |
379 | for i, v in ipairs(val) do atbl[nkeys + i] = v end | 386 | for i, v in ipairs(val) do atbl[nskeys + i] = v end |
380 | else | 387 | else |
381 | atbl[nkeys + 1] = val | 388 | atbl[nskeys + 1] = val |
382 | end | 389 | end |
383 | self.mt[self.key .. "_set"](self.obj, unpack(atbl)) | 390 | self.mt[self.key .. "_set"](self.obj, unpack(atbl)) |
384 | else | 391 | else |
385 | if self.nvals > 1 and type(val) == "table" then | 392 | if self.nsvals > 1 and type(val) == "table" then |
386 | -- somewhat less slow but still slow path | 393 | -- somewhat less slow but still slow path |
387 | self.mt[self.key .. "_set"](self.obj, key, unpack(val)) | 394 | self.mt[self.key .. "_set"](self.obj, key, unpack(val)) |
388 | else | 395 | else |
@@ -403,11 +410,11 @@ local prop_proxy_meta = { | |||
403 | 410 | ||
404 | -- each __properties field looks like this: | 411 | -- each __properties field looks like this: |
405 | -- | 412 | -- |
406 | -- { NUMBER_OF_KEYS, NUMBER_OF_VALUES, GETTABLE, SETTABLE } | 413 | -- { NUM_GET_KEYS, NUM_SET_KEYS, NUM_GET_VALS, NUM_SET_VALS, GETTABLE, SETTABLE } |
407 | -- | 414 | -- |
408 | -- the last two are booleans (determining if the property can be get and set). | 415 | -- the last two are booleans (determining if the property can be get and set). |
409 | ffi.metatype("Eo", { | 416 | ffi.metatype("Eo", { |
410 | -- handles property getting with no keys and also property setting with keys | 417 | -- handles property getting with no keys and also properties with keys |
411 | __index = function(self, key) | 418 | __index = function(self, key) |
412 | local mt = get_obj_mt(self) | 419 | local mt = get_obj_mt(self) |
413 | if mt == nil then return nil end | 420 | if mt == nil then return nil end |
@@ -416,18 +423,19 @@ ffi.metatype("Eo", { | |||
416 | if not pp then | 423 | if not pp then |
417 | return mt[key] | 424 | return mt[key] |
418 | end | 425 | end |
419 | local nkeys, nvals = pp[1], pp[2] | 426 | local ngkeys, nskeys = pp[1], pp[2] |
420 | if nkeys ~= 0 then | 427 | if ngkeys ~= 0 or nskeys ~= 0 then |
421 | -- proxy - slow path, but no way around it | 428 | -- proxy - slow path, but no way around it |
422 | -- basically the proxy is needed because we want nice syntax and | 429 | -- basically the proxy is needed because we want nice syntax and |
423 | -- lua can't do it by default. so we help ourselves a bit with this | 430 | -- lua can't do it by default. so we help ourselves a bit with this |
424 | return setmetatable({ nkeys = nkeys, nvals = nvals, | 431 | return setmetatable({ ngkeys = ngkeys, nskeys = nskeys, |
425 | obj = self, key = key, mt = mt }, prop_proxy_meta) | 432 | ngvals = pp[3], nsvals = pp[4], obj = self, key = key, |
433 | mt = mt }, prop_proxy_meta) | ||
426 | end | 434 | end |
427 | if not pp[3] then | 435 | if not pp[5] then |
428 | error("property '" .. key .. "' is not gettable", 2) | 436 | error("property '" .. key .. "' is not gettable", 2) |
429 | end | 437 | end |
430 | if nvals > 1 then | 438 | if pp[3] > 1 then |
431 | return { mt[key .. "_get"](self) } | 439 | return { mt[key .. "_get"](self) } |
432 | else | 440 | else |
433 | return mt[key .. "_get"](self) | 441 | return mt[key .. "_get"](self) |
@@ -443,13 +451,14 @@ ffi.metatype("Eo", { | |||
443 | if not pp then | 451 | if not pp then |
444 | error("no such property '" .. key .. "'", 2) | 452 | error("no such property '" .. key .. "'", 2) |
445 | end | 453 | end |
446 | if not pp[4] then | 454 | if not pp[6] then |
447 | error("property '" .. key .. "' is not settable", 2) | 455 | error("property '" .. key .. "' is not settable", 2) |
448 | end | 456 | end |
449 | if pp[1] ~= 0 then | 457 | local nkeys = pp[2] |
450 | error("property '" .. key .. "' requires " .. pp[1] .. " keys", 2) | 458 | if nkeys ~= 0 then |
459 | error("property '" .. key .. "' requires " .. nkeys .. " keys", 2) | ||
451 | end | 460 | end |
452 | local nvals = pp[2] | 461 | local nvals = pp[4] |
453 | if nvals > 1 and type(val) == "table" then | 462 | if nvals > 1 and type(val) == "table" then |
454 | mt[key .. "_set"](self, unpack(val)) | 463 | mt[key .. "_set"](self, unpack(val)) |
455 | else | 464 | else |