LuaUserData.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace LuaInterface
  5. {
  6. public class LuaUserData : LuaBase
  7. {
  8. //internal int _Reference;
  9. //private Lua _Interpreter;
  10. public LuaUserData(int reference, LuaState interpreter)
  11. {
  12. _Reference = reference;
  13. _Interpreter = interpreter;
  14. }
  15. //~LuaUserData()
  16. //{
  17. // if (_Reference != 0)
  18. // _Interpreter.dispose(_Reference);
  19. //}
  20. /*
  21. * Indexer for string fields of the userdata
  22. */
  23. public object this[string field]
  24. {
  25. get
  26. {
  27. return _Interpreter.getObject(_Reference, field);
  28. }
  29. set
  30. {
  31. _Interpreter.setObject(_Reference, field, value);
  32. }
  33. }
  34. /*
  35. * Indexer for numeric fields of the userdata
  36. */
  37. public object this[object field]
  38. {
  39. get
  40. {
  41. return _Interpreter.getObject(_Reference, field);
  42. }
  43. set
  44. {
  45. _Interpreter.setObject(_Reference, field, value);
  46. }
  47. }
  48. /*
  49. * Calls the userdata and returns its return values inside
  50. * an array
  51. */
  52. public object[] Call(params object[] args)
  53. {
  54. return _Interpreter.callFunction(this, args);
  55. }
  56. /*
  57. * Pushes the userdata into the Lua stack
  58. */
  59. internal void push(IntPtr luaState)
  60. {
  61. LuaDLL.lua_getref(luaState, _Reference);
  62. }
  63. public override string ToString()
  64. {
  65. return "userdata";
  66. }
  67. //public override bool Equals(object o)
  68. //{
  69. // if (o is LuaUserData)
  70. // {
  71. // LuaUserData l = (LuaUserData)o;
  72. // return _Interpreter.compareRef(l._Reference, _Reference);
  73. // }
  74. // else return false;
  75. //}
  76. //public override int GetHashCode()
  77. //{
  78. // return _Reference;
  79. //}
  80. }
  81. }