@@ -38,39 +38,6 @@ import {
3838import { luaValueToJS } from "../space_lua/runtime.ts" ;
3939import { jsToLuaValue } from "../space_lua/runtime.ts" ;
4040
41- function handleVarargSync ( env : LuaEnv ) : LuaValue [ ] | Promise < LuaValue [ ] > {
42- const varargs = env . get ( "..." ) ;
43- if ( varargs instanceof Promise ) {
44- return handleVarargAsync ( varargs ) ;
45- }
46- if ( varargs instanceof LuaTable ) {
47- const args = [ ] ;
48- for ( let i = 1 ; i <= varargs . length ; i ++ ) {
49- const val = varargs . get ( i ) ;
50- if ( val instanceof Promise ) {
51- return handleVarargAsync ( varargs ) ;
52- }
53- args . push ( val ) ;
54- }
55- return args ;
56- }
57- return [ ] ;
58- }
59-
60- async function handleVarargAsync (
61- varargs : Promise < LuaValue > | LuaTable ,
62- ) : Promise < LuaValue [ ] > {
63- const resolvedVarargs = await varargs ;
64- if ( resolvedVarargs instanceof LuaTable ) {
65- const args = [ ] ;
66- for ( let i = 1 ; i <= resolvedVarargs . length ; i ++ ) {
67- args . push ( await resolvedVarargs . get ( i ) ) ;
68- }
69- return args ;
70- }
71- return [ ] ;
72- }
73-
7441async function handleTableFieldSync (
7542 table : LuaTable ,
7643 field : any ,
@@ -91,18 +58,13 @@ async function handleTableFieldSync(
9158 break ;
9259 }
9360 case "ExpressionField" : {
94- if ( field . value . type === "Variable" && field . value . name === "..." ) {
95- const varargs = await handleVarargSync ( env ) ;
96- varargs . forEach ( ( val , i ) => table . set ( i + 1 , val , sf ) ) ;
97- } else {
98- const value = await evalExpression ( field . value , env , sf ) ;
99- if ( value instanceof LuaMultiRes ) {
100- for ( const val of value . values ) {
101- table . set ( table . length + 1 , val , sf ) ;
102- }
103- } else {
104- table . set ( table . length + 1 , singleResult ( value ) , sf ) ;
61+ const value = await evalExpression ( field . value , env , sf ) ;
62+ if ( value instanceof LuaMultiRes ) {
63+ for ( const val of value . values ) {
64+ table . set ( table . length + 1 , val , sf ) ;
10565 }
66+ } else {
67+ table . set ( table . length + 1 , singleResult ( value ) , sf ) ;
10668 }
10769 break ;
10870 }
@@ -229,16 +191,6 @@ export function evalExpression(
229191 case "TableConstructor" : {
230192 return Promise . resolve ( ) . then ( async ( ) => {
231193 const table = new LuaTable ( ) ;
232- if (
233- e . fields . length === 1 &&
234- e . fields [ 0 ] . type === "ExpressionField" &&
235- e . fields [ 0 ] . value . type === "Variable" &&
236- e . fields [ 0 ] . value . name === "..."
237- ) {
238- const varargs = await handleVarargSync ( env ) ;
239- varargs . forEach ( ( val , i ) => table . set ( i + 1 , val , sf ) ) ;
240- return table ;
241- }
242194
243195 for ( const field of e . fields ) {
244196 await handleTableFieldSync ( table , field , env , sf ) ;
@@ -396,38 +348,6 @@ function evalPrefixExpression(
396348 const handleFunctionCall = (
397349 prefixValue : LuaValue ,
398350 ) : LuaValue | Promise < LuaValue > => {
399- // Special handling for f(...) - propagate varargs
400- if (
401- e . args . length === 1 && e . args [ 0 ] . type === "Variable" &&
402- e . args [ 0 ] . name === "..."
403- ) {
404- // TODO: Clean this up
405- const varargs = env . get ( "..." ) ;
406- const resolveVarargs = async ( ) => {
407- const resolvedVarargs = await Promise . resolve ( varargs ) ;
408- if ( resolvedVarargs instanceof LuaTable ) {
409- const args = [ ] ;
410- for ( let i = 1 ; i <= resolvedVarargs . length ; i ++ ) {
411- const val = await Promise . resolve ( resolvedVarargs . get ( i ) ) ;
412- args . push ( val ) ;
413- }
414- return args ;
415- }
416- return [ ] ;
417- } ;
418-
419- if ( prefixValue instanceof Promise ) {
420- return prefixValue . then ( async ( resolvedPrefix ) => {
421- const args = await resolveVarargs ( ) ;
422- return luaCall ( resolvedPrefix , args , e . ctx , sf . withCtx ( e . ctx ) ) ;
423- } ) ;
424- } else {
425- return resolveVarargs ( ) . then ( ( args ) =>
426- luaCall ( prefixValue , args , e . ctx , sf . withCtx ( e . ctx ) )
427- ) ;
428- }
429- }
430-
431351 // Normal argument handling for hello:there(a, b, c) type calls
432352 if ( e . name ) {
433353 selfArgs = [ prefixValue ] ;
0 commit comments