Support of enums in API generator
This commit is contained in:
parent
fda800fd26
commit
2c226b90e2
1 changed files with 16 additions and 1 deletions
|
|
@ -164,13 +164,16 @@ proc incDerivedCount(types: var Table[string, GodotType],
|
||||||
types.incDerivedCount(typ.baseName)
|
types.incDerivedCount(typ.baseName)
|
||||||
|
|
||||||
proc toNimType(godotType: string): string =
|
proc toNimType(godotType: string): string =
|
||||||
case godotType:
|
result = case godotType:
|
||||||
of "float": "float64"
|
of "float": "float64"
|
||||||
of "int": "int64"
|
of "int": "int64"
|
||||||
of "String": "string"
|
of "String": "string"
|
||||||
of "File": "godottypes.File"
|
of "File": "godottypes.File"
|
||||||
else: godotType
|
else: godotType
|
||||||
|
|
||||||
|
if result.startsWith("enum."):
|
||||||
|
result = if result == "enum.Error": "Error" else: "int64"
|
||||||
|
|
||||||
proc toNimType(types: Table[string, GodotType], godotType: string): string =
|
proc toNimType(types: Table[string, GodotType], godotType: string): string =
|
||||||
let origType =
|
let origType =
|
||||||
if godotType.contains(','):
|
if godotType.contains(','):
|
||||||
|
|
@ -878,6 +881,18 @@ proc genApi*(targetDir: string, apiJsonFile: string) =
|
||||||
if typ.isSingleton:
|
if typ.isSingleton:
|
||||||
genSingletonWithDerived(tree, typ, types)
|
genSingletonWithDerived(tree, typ, types)
|
||||||
|
|
||||||
|
if "enums" in obj:
|
||||||
|
# Quite often Godot enums are flags that need to be bitwise ORed
|
||||||
|
# Nim's enums don't serve well for that purpose, so we just generate
|
||||||
|
# integer constants. The only enum used in API is Error.
|
||||||
|
for enumDef in obj["enums"]:
|
||||||
|
let uniqueConstants = newJObject()
|
||||||
|
for k, v in enumDef["values"]:
|
||||||
|
if k notin obj["constants"]:
|
||||||
|
uniqueConstants[k] = v
|
||||||
|
if uniqueConstants.len > 0:
|
||||||
|
tree.add(makeConstSection(uniqueConstants))
|
||||||
|
|
||||||
# first, generate declarations only for ease of
|
# first, generate declarations only for ease of
|
||||||
# human readability of the file
|
# human readability of the file
|
||||||
for property in obj["properties"]:
|
for property in obj["properties"]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue