Skip to content

loadstring behaves differently #32

@dgjxqz

Description

@dgjxqz

3 Issues:

  1. Arguments not passed to the top level function of a parsed chunk (via ...).
  2. Parsed chunk has it's own global environment.
  3. Lua understands calling function with func()() but javascript needs () around i.e. (func())()

From command line,

% lua -e 'var=123 loadstring"print(var,...)"(456)'

gives:

123     456

In chrome,

<script src=lua+parser.min.js></script>
<script>lua_load('var=123 loadstring"print(var,...)"(456)')();</script>
<script>lua_load('var=123 (loadstring"print(var,...)")(456)')();</script>
<script>lua_load('var=123 (loadstring"print(var)")(456)')();</script>

gives:

Uncaught Error: Parse error on line 1:
...print(var,...)"(456)
-----------------------^
Expecting '(', ':', '.', 'STRING', '{', '[', got 'EOF' lua+parser.min.js:127
Uncaught ReferenceError: varargs is not defined
undefined lua+parser.min.js:16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions