Results 1 to 2 of 2

Thread: I was wrong about dofile. (maybe)

  1. #1
    Lesser Knight
    Join Date
    Dec 2006
    Location
    United States
    Posts
    47

    Unhappy I was wrong about dofile. (maybe)

    Does RunScript (as the name implies) just run the given source file regardless of whether it has already been executed? dofile does just that. The package table (which is now disabled in Novashell) is preferable because it only executes a script once. I made a replacement of require that relies on RunScript:

    Code:
    do
        local scripts = {}
    
        function require(filename)
            if not scripts[filename] then
                scripts[filename] = true
                RunScript(filename)
            end
        end
    end

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Yes, you're right, RunScript will load multiple times. I'll add this function to system/misc_utils.lua.

    Note: Probably shouldn't use it from any entity namespace, as it will mark it as loaded but it will actually be destroyed when the entity is... but really, global type scripts shouldn't be loaded from entity scripts anyway.
    Seth A. Robinson
    Robinson Technologies

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •