Jump to content
  • 0

Help!


Pyxe

Question

7 answers to this question

Recommended Posts

6 hours ago, ForbiddenSaga said:

debug.getinfo() might be able to help

Example please?

@Lenn1 @CmP

_______________________________________________
added 2 minutes later

@Lenn1 @CmP

_______________________________________________
added 3 minutes later

@Lenn1 @CmP

 

_______________________________________________
added 4 minutes later

Oops sorry gameguardian website very slow now

Link to comment
Share on other sites

2 hours ago, Pyxe said:

Example please?

@Lenn1 @CmP

_______________________________________________
added 2 minutes later

@Lenn1 @CmP

_______________________________________________
added 3 minutes later

@Lenn1 @CmP

 

_______________________________________________
added 4 minutes later

Oops sorry gameguardian website very slow now

usually when a script is hooked or is loaded by another script, it will return a value 1 level above when debug.getinfo() is called.
For example,
debug.getinfo(1) means level 1, that's your current script.
Now if there's another script using load() on your script, debug.getinfo(2) would have a value, if there's none it would return null when called.

but do be aware, this is not 100% secure, some pretty good programmer people can overwrite the data.

as for the logging feature that enyby made built into the game guardian, i don't think there's anyway to check that.

Link to comment
Share on other sites

16 minutes ago, Pyxe said:

So like how would i implement that into my script?

Really man?
i can spoonfeed you, but if you don't know what you're doing. It might backfires.

Put this at the top of your script before anything else.

if (debug.getinfo(2) ~= nil) then print ("Hook is attached.") os.exit() end

Link to comment
Share on other sites

5 minutes ago, ForbiddenSaga said:

Really man?
i can spoonfeed you, but if you don't know what you're doing. It might backfires.

Put this at the top of your script before anything else.

if (debug.getinfo(2) ~= nil) then print ("Hook is attached.") os.exit() end

Thank you, i really appreciate you helping me.

Link to comment
Share on other sites

Introspective Facilities

The main introspective function in the debug library is the debug.getinfo function. Its first parameter may be a function or a stack level. When you call debug.getinfo(foo) for some function foo, you get a table with some data about that function. The table may have the following fields:

  • source --- Where the function was defined. If the function was defined in a string (through loadstring),source is that string. If the function was defined in a file, source is the file name prefixed with a `@´.
  • short_src --- A short version of source (up to 60 characters), useful for error messages.
  • linedefined --- The line of the source where the function was defined.
  • what --- What this function is. Options are "Lua" if foo is a regular Lua function, "C" if it is a C function, or "main" if it is the main part of a Lua chunk.
  • name --- A reasonable name for the function.
  • namewhat --- What the previous field means. This field may be "global""local""method""field", or "" (the empty string). The empty string means that Lua did not find a name for the function.
  • nups --- Number of upvalues of that function.
  • func --- The function itself; see later.

When foo is a C function, Lua does not have much data about it. For such functions, only the fields whatname, and namewhat are relevant.

When you call debug.getinfo(n) for some number n, you get data about the function active at that stack level. For instance, if n is 1, you get data about the function doing the call. (When n is 0, you get data about getinfo itself, a C function.) If n is larger than the number of active functions in the stack, debug.getinforeturns nil. When you query an active function, calling debug.getinfo with a number, the result table has an extra field, currentline, with the line where the function is at that moment. Moreover, func has the function that is active at that level.

The field name is tricky. Remember that, because functions are first-class values in Lua, a function may not have a name, or may have several names. Lua tries to find a name for a function by looking for a global variable with that value, or else looking into the code that called the function, to see how it was called. This second option works only when we call getinfo with a number, that is, we get information about a particular invocation.

The getinfo function is not efficient. Lua keeps debug information in a form that does not impair program execution; efficient retrieval is a secondary goal here. To achieve better performance, getinfo has an optional second parameter that selects what information to get. With this parameter, it does not waste time collecting data that the user does not need. The format of this parameter is a string, where each letter selects a group of data, according to the following table:

`n´ selects fields name and namewhat
`f´ selects field func
`S´ selects fields sourceshort_srcwhat, and linedefined
`l´ selects field currentline
`u´ selects field nup

The following function illustrates the use of debug.getinfo. It prints a primitive traceback of the active stack:

    function traceback ()
      local level = 1
      while true do
        local info = debug.getinfo(level, "Sl")
        if not info then break end
        if info.what == "C" then   -- is a C function?
          print(level, "C function")
        else   -- a Lua function
          print(string.format("[%s]:%d",
                              info.short_src, info.currentline))
        end
        level = level + 1
      end
    end

It is not difficult to improve this function, including more data from getinfo. Actually, the debug library offers such an improved version, debug.traceback. Unlike our version, debug.traceback does not print its result; instead, it returns a string.

https://www.lua.org/pil/23.1.html


Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.