How to use the lua-types.callExpression function in lua-types

To help you get started, we’ve selected a few lua-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ark120202 / babel-lua / packages / babel-plugin-lua-generator / src / transformers / expressions.js View on Github external
export function UnaryExpression(node) {
  switch (node.operator) {
    case 'void':
      return t.binaryExpression('and', this.transform(node.argument), t.nilLiteral());
    case 'delete':
      return t.assignmentStatement([this.transform(node.argument)], [t.nilLiteral()]);
    case '!':
      return t.unaryExpression('not', this.transform(node.argument));
    case '+':
      return t.callExpression(t.identifier('tonumber'), [this.transform(node.argument)]);
    case '-':
    case '~':
      return t.unaryExpression(node.operator, this.transform(node.argument));
    default:
      // FIXME: Use path.buildCodeFrameError
      throw new Error(`${node.operator} is unsupported unary operator`);
  }
}
github ark120202 / babel-lua / packages / babel-plugin-lua-generator / src / transformers / statements.js View on Github external
export function ForOfStatement(node) {
  const variable = bt.isVariableDeclaration(node.left)
    ? this.transform(node.left.declarations[0].id)
    : this.transform(node.left);
  const helper = t.memberExpression(t.identifier('Reflect'), ':', t.identifier('__forOf'));

  let uid = node[FOR_OF_UID];
  // TODO: Apply visitor before transform in testing
  if (uid == null && process.env.NODE_ENV === 'test') uid = bt.identifier('_');
  if (uid == null) throw new Error('UID not found for ForOfStatement transform');

  return t.forGenericStatement(
    [this.transform(uid), variable],
    [t.callExpression(helper, [this.transform(node.right)])],
    this.transformBlock(node.body),
  );
}
github ark120202 / babel-lua / packages / babel-plugin-lua-generator / src / transformers / expressions.js View on Github external
export function CallExpression(node) {
  if (bt.isIdentifier(node.callee, { name: '__lua' }) && node.arguments.length === 1) {
    const argument = node.arguments[0];
    // TODO: Use path.evaluate, ref: https://github.com/babel/babel/blob/6.x/packages/babel-plugin-transform-eval/src/index.js
    if (bt.isStringLiteral(argument)) {
      return t.luaRaw(argument.value);
    }
  }

  return t.callExpression(this.transform(node.callee), this.transformList(node.arguments));
}
github ark120202 / babel-lua / packages / babel-plugin-lua-generator / src / transformers / statements.js View on Github external
export function ForInStatement(node) {
  const variable = bt.isVariableDeclaration(node.left)
    ? this.transform(node.left.declarations[0].id)
    : this.transform(node.left);

  return t.forGenericStatement(
    [variable],
    [t.callExpression(t.identifier('pairs'), [this.transform(node.right)])],
    this.transformBlock(node.body),
  );
}