From e64632be1aa938c865d06acfcf6641b75ecb42ac Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 29 Aug 2018 14:19:16 -0700 Subject: Switched "as_lua_id" to not add an underscore by default, and just add it manually to variables and A_ as a prefix to actions. Now, by default, classes and method calls don't use the A_ prefix, which means nomsu can more easily play nice with regular Lua objects. --- lib/object.nom | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/object.nom') diff --git a/lib/object.nom b/lib/object.nom index 22321b3..47a7839 100644 --- a/lib/object.nom +++ b/lib/object.nom @@ -44,7 +44,7 @@ test: assume ((%d::bark) == "Bark! Bark!") compile [my action %actions %body] to: lua> ".." - local fn_name = "A"..string.as_lua_id(\%actions[1].stub) + local fn_name = string.as_lua_id(\%actions[1].stub) local \%args = table.map(\%actions[1]:get_args(), function(a) return tostring(nomsu:compile(a)) end) table.insert(\%args, \(\%me as lua id)) local lua = LuaCode(tree.source, "class.", fn_name, " = ", \(..) @@ -52,7 +52,7 @@ compile [my action %actions %body] to: ..) for i=2,#\%actions do local alias = \%actions[i] - local alias_name = "A"..string.as_lua_id(alias.stub) + local alias_name = string.as_lua_id(alias.stub) local \%alias_args = table.map(alias:get_args(), function(a) return tostring(nomsu:compile(a)) end) table.insert(\%alias_args, \(\%me as lua id)) lua:append("\\nclass.", alias_name, " = ") @@ -78,15 +78,15 @@ compile [object %classname extends %parent %class_body] to: __tostring=function(cls) return cls.name end, __call=function(cls, inst) inst = setmetatable(inst or {}, cls) - if inst.A_set_up then - inst:A_set_up() + if inst.set_up then + inst:set_up() end return inst end, }) - nomsu["A"..string.as_lua_id("new "..class.name)] = class - nomsu["A"..string.as_lua_id("new "..class.name.." 1")] = class - nomsu["A"..string.as_lua_id(class.name)] = function() return class end + nomsu["A_"..string.as_lua_id("new "..class.name)] = class + nomsu["A_"..string.as_lua_id("new "..class.name.." 1")] = class + nomsu["A_"..string.as_lua_id(class.name)] = function() return class end class.__index = class class.class = class class.__tostring = function(inst) @@ -104,7 +104,7 @@ compile [object %classname extends %parent %class_body] to: ["__ipairs"]="__ipairs", ["__pairs"]="__pairs", } for stub,metamethod in pairs(metamethod_map) do - class[metamethod] = class["A"..string.as_lua_id(stub)] + class[metamethod] = class[string.as_lua_id(stub)] end end -- cgit v1.2.3