【问题标题】:Lua map value as constructorLua 映射值作为构造函数
【发布时间】:2018-10-29 01:28:32
【问题描述】:

我想将我的构造函数存储在 map 中,以便创建对象,即在 foreach 中为不同的定义类型

类似的东西

ObjByType = { "integer" = IntegerObj, "float" = FloatObj }
x = ObjByType["integer"]( arg1, arg2, arg3 )

【问题讨论】:

    标签: arrays dictionary constructor lua


    【解决方案1】:

    使用这个语法:

    ObjByType = { integer = IntegerObj, float = FloatObj }
    

    如果字段不是简单的单词,则为这个:

    ObjByType = { ["integer"] = IntegerObj, ["float"] = FloatObj }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 2013-01-14
      • 2019-05-13
      • 2010-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多