Skip to content

Commit 7dd966d

Browse files
committed
Make struct fields optional if they have default values (fixes #85)
1 parent 22ec6c0 commit 7dd966d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

__tests__/test-data/offline-sites/gmod-wiki/struct-custom-entity-fields.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ This can also be set from map, see <page>Sandbox Specific Mapping</page></item>
3434
<item name="CanProperty" type="function">Documented at <page>ENTITY:CanProperty</page>.</item>
3535
<item name="CanTool" type="function">Documented at <page>ENTITY:CanTool</page>.</item>
3636
37+
<item name="DoNotDuplicate" type="boolean" default="false" realm="server">If set, the entity will not be duplicated via the built-in duplicator system.</item>
38+
3739
<item name="CalcAbsolutePosition" type="function">Documented at <page>ENTITY:CalcAbsolutePosition</page>.</item>
3840
<item name="RenderOverride" type="function">Documented at <page>ENTITY:RenderOverride</page>.</item>
3941
@@ -117,6 +119,10 @@ Custom_Entity_Fields.CanProperty = nil
117119
---@type function
118120
Custom_Entity_Fields.CanTool = nil
119121
122+
---If set, the entity will not be duplicated via the built-in duplicator system.
123+
---@type boolean?
124+
Custom_Entity_Fields.DoNotDuplicate = false
125+
120126
---Documented at ENTITY:CalcAbsolutePosition.
121127
---@type function
122128
Custom_Entity_Fields.CalcAbsolutePosition = nil

src/api-writer/glua-api-writer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ export class GluaApiWriter {
325325
api += `---${wrapInComment(field.description)}\n`;
326326

327327
const type = GluaApiWriter.transformType(field.type, field.callback);
328-
api += `---@type ${type}\n`;
328+
const optional = field.default ? '?' : '';
329+
api += `---@type ${type}${optional}\n`;
329330
api += `${struct.name}.${GluaApiWriter.safeName(field.name)} = ${field.default ? this.writeType(type, field.default) : 'nil'}\n\n`;
330331
}
331332

0 commit comments

Comments
 (0)