diff --git a/builtins_base.js b/builtins_base.js index fbfa82a..9fbd02f 100644 --- a/builtins_base.js +++ b/builtins_base.js @@ -314,21 +314,28 @@ module.exports = { '__dfhack_random.init': 'none', '__dfhack_random.random': 'number', '__dfhack_random.drandom': 'number', + 'dfhack.units.getCasteProfessionName': 'string', + 'dfhack.units.getNemesis': 'df.nemesis_record', + 'dfhack.units.getPosition': { _type:'tuple', _tuple:['number', 'number', 'number'] }, + 'dfhack.units.getProfessionColor': 'number', 'dfhack.units.getProfessionName': 'string', + 'dfhack.units.getVisibleName': 'df.language_name', + 'dfhack.units.isActive': 'bool', + 'dfhack.units.isBaby': 'bool', + 'dfhack.units.isChild': 'bool', 'dfhack.units.isCitizen': 'bool', + 'dfhack.units.isDead': 'bool', + 'dfhack.units.isDiplomat': 'bool', + 'dfhack.units.isFemale': 'bool', + 'dfhack.units.isMale': 'bool', + 'dfhack.units.isMarkedForSlaughter': 'bool', + 'dfhack.units.isMerchant': 'bool', + 'dfhack.units.isOpposedToLife': 'bool', 'dfhack.units.isOwnCiv': 'bool', - 'dfhack.units.getVisibleName': 'df.language_name', - 'dfhack.units.getProfessionColor': 'number', - 'dfhack.units.getNemesis': 'df.nemesis_record', - 'dfhack.units.getPosition': { _type:'tuple', _tuple:['number', 'number', 'number'] }, - 'dfhack.units.getCasteProfessionName': 'string', - 'dfhack.units.setNickname': 'none', 'dfhack.units.isOwnGroup': 'bool', + 'dfhack.units.isOwnRace': 'bool', 'dfhack.units.isSane': 'bool', - 'dfhack.units.isDead': 'bool', - 'dfhack.units.isOpposedToLife': 'bool', - 'dfhack.units.isMale': 'bool', - 'dfhack.units.isFemale': 'bool', + 'dfhack.units.setNickname': 'none', 'dfhack.units.getNoblePositions': { _type: 'table', _array: { @@ -379,6 +386,7 @@ module.exports = { 'dfhack.maps.ensureTileBlock': 'df.map_block', 'dfhack.maps.getTileType': 'df.tiletype', 'dfhack.maps.getTileFlags': { _type:'tuple', _tuple:['df.tile_designation', 'df.tile_occupancy'] }, + 'dfhack.maps.isValidTilePos': 'bool', 'dfhack.maps.spawnFlow': 'df.flow_info', 'dfhack.maps.enableBlockUpdates': 'none', 'dfhack.burrows.setAssignedUnit': 'none', diff --git a/index.js b/index.js index d827f25..3e8a1fd 100644 --- a/index.js +++ b/index.js @@ -121,7 +121,7 @@ function deepEqual(a, b, ctx, line) { if (b == 'null') { return true; } - if (a && b && (Object.hasOwnProperty.call(a, '_value') || Object.hasOwnProperty.call(b, '_value')) && (a._type||a) == (b._type||b)) { + if (a && b && (Object.hasOwnProperty.call(a, '_value') || Object.hasOwnProperty.call(b, '_value') || (a._type||a) == 'number' || (b._type||b) == 'number') && (a._type||a) == (b._type||b)) { return true; } if (typeof a != typeof b) { @@ -1764,6 +1764,9 @@ function merge(a, b, ctx, line, quiet) { if (b == 'null') { return a; } + if ((a._type||a) == 'number' && (b._type||b) == 'bool') { + return 'number'; // allow assigning true/false to bitfields + } if (((a._type||a) == '__arg' && isargtype(b._type||b)) || ((b._type||b) == '__arg' && isargtype(a._type||a))) { return '__arg'; } @@ -2553,7 +2556,7 @@ function processAST(body, ctx) { var t = checktype(clause.condition, ctx2, { in_if:true }); // if (t == '__unknown') // err(b.loc.start.line, 'type of expression is unknown', chalk.bold(sub(clause.condition.range))); - if (t && t._type == 'bool' && !t._value) { + if (t && t._type == 'bool' && Object.hasOwnProperty.call(t, '_value') && !t._value) { if (verbose > 1) { note(clause.loc.start.line, 'skipping if statement', chalk.bold(sub(clause.condition.range)), '(condition is always false)'); } diff --git a/luacheck.sh b/luacheck.sh index bf75ec9..20f57eb 100755 --- a/luacheck.sh +++ b/luacheck.sh @@ -48,6 +48,9 @@ if (( $# > 0 )); then done else find "$dfhack_dir/scripts" -name '*.lua' -print0 | while IFS= read -r -d $'\0' script_path; do + if grep -qF "luacheck:skip-entirely" "$script_path"; then + continue + fi node "$luacheck_dir/index.js" $args -v "$dfhack_version" -S "$dfhack_dir/scripts" -I "$dfhack_dir/library/lua" -I "$dfhack_dir/scripts" -p dfhack "$script_path" if (( $? > 0 )); then had_error=1; fi done diff --git a/prepare.js b/prepare.js index e4c09de..096b57d 100644 --- a/prepare.js +++ b/prepare.js @@ -490,6 +490,10 @@ pending_index_enums.forEach(function(e) { Object.keys(rootctx.functions || {}).forEach(function(f) { var path = f.split(/\./g); var t = rootctx.types; + if (path.length == 2 && path[0] == 'string') { + rootctx.functions['__arg.' + path[1]] = rootctx.functions[f]; + } + for (var i = 0; i < path.length - 1; i++) { if (!t[path[i]]) { t[path[i]] = {