Skip to content

Commit

Permalink
Move resultIsOutput into result
Browse files Browse the repository at this point in the history
  • Loading branch information
smack0007 committed Sep 10, 2024
1 parent 4c0e541 commit 354d3b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tools/codegen/SDL/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ export const functions: CodeGenFunctions = {
},
result: {
type: "Uint8*",
isOutput: true,
},
resultIsOutput: true,
implementation: GET_KEYBOARD_STATE,
},
SDL_GetRendererInfo: {
Expand Down Expand Up @@ -1041,9 +1041,9 @@ export const functions: CodeGenFunctions = {
},
result: {
type: "SDL_AudioSpec*",
isOutput: true,
},
checkForError: true,
resultIsOutput: true,
implementation: LOADWAV_RW,
},
SDL_LockSurface: {
Expand Down
8 changes: 4 additions & 4 deletions tools/codegen/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1624,15 +1624,15 @@ import { f32, f64, i32, InitOptions, int, Int, TypedArray, u16, u32, U32, u64, u
outputParams[0][1]
);

if (func.resultIsOutput) {
if (func.result.isOutput) {
returnType = "[" + returnType + ", " + outputParam + "]";
} else {
returnType = outputParam;
}
} else if (outputParams.length > 1) {
returnType =
"[" +
(func.resultIsOutput ? returnType + ", " : "") +
(func.result.isOutput ? returnType + ", " : "") +
outputParams
.map(([_, outputParam]) =>
mapFunctionReturnTypeFromOutputParam(
Expand Down Expand Up @@ -1793,7 +1793,7 @@ import { f32, f64, i32, InitOptions, int, Int, TypedArray, u16, u32, U32, u64, u
if (outputParams.length === 0) {
lines.push("return _result;");
} else if (outputParams.length === 1) {
if (func.resultIsOutput) {
if (func.result.isOutput) {
lines.push(`return [_result, ${outputParams[0][0]}];`);
} else {
lines.push(`return ${outputParams[0][0]};`);
Expand All @@ -1803,7 +1803,7 @@ import { f32, f64, i32, InitOptions, int, Int, TypedArray, u16, u32, U32, u64, u
.map(([paramName, _]) => `${paramName}.value`)
.join(", ");

if (func.resultIsOutput) {
if (func.result.isOutput) {
lines.push(`return [_result, ${outputParamNames}];`);
} else {
lines.push(`return [${outputParamNames}];`);
Expand Down
10 changes: 5 additions & 5 deletions tools/codegen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export interface CodeGenFunctionResult {

// If set this type will be used as the script type.
overrideType?: string;

// If any parameter is marked as an output parameter than the return value
// will generally be discarded. This flag specifies that the return value
// should not be discarded when there are output parameters.
isOutput?: boolean;
}

export interface CodeGenFunction {
Expand All @@ -65,11 +70,6 @@ export interface CodeGenFunction {

result: CodeGenFunctionResult;

// If any parameter is marked as an output parameter than the return value
// will generally be discarded. This flag specifies that the return value
// should not be discarded when there are output parameters.
resultIsOutput?: boolean;

overloads?: ReadonlyArray<{
parameters?: Record<string, Partial<CodeGenFunctionParam>>;
result?: Partial<CodeGenFunctionResult>;
Expand Down

0 comments on commit 354d3b9

Please sign in to comment.