Skip to content

debug.traceback of loadstring get unknown file #1259

@pilaoda

Description

@pilaoda

My traceback:

Script Runtime Error: unknown:743: attempt to perform arithmetic on local 'c' (a string value)
stack traceback:
    unknown:743: in function 'handler'
    unknown:189: in function <unknown:186>

My code:

local encryptedCode = "XXXXXX"
local decryptedCode = decrypt(encryptedCode)
loadstring(decryptedCode , "sys/Cheat.lua")()

What I have done is encrypt the generated lua file, and use loadstring after decryption.
I already set the file path as the second parameter chunkname of loadstring, but the traceback still be replaced by this code:

[result] = string.gsub(result, '(%[string "[^"]+"%]):(%d+)', (file, line) =>

What I expect is using the sourcemap with the chunkname I set in loadstring.
I have two ideas to achieve this:

  1. Assume the chunkname is the lua path, and replace the traceback substring [string "xx/xx.lua"]:22 to xx/xx.ts:10 or [string "xx/xx.ts"]:10
  2. Provide a custom replacer of loadstring for users to implement by themselves.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions