Skip to content

Make stdlib functions easily accessable #18

@DynamicCake

Description

@DynamicCake

I want a way to get a function while knowing it hasn't been interfered with by the user. To solve this problem, one could preemptively run glua.ref_get(lua, ["getmetatable"]) before user scripts, but this being the only way causes some problems. Creating a helper function that checks for a certain metatable field would require the helper function to accept a getmetatable: ValueRef. (Since running glua.ref_get(lua, ["getmetatable"]) in the function could yield a possibly tampered with function.)

To solve this problem, I propose that glua should expose the stdlib functions through a module that could be called lib (or something else). lib would have functions that could get standard library lua functions.

Example usage:

fn check_magic(lua: Lua, table: ValueRef) -> Bool {
  let getmetatable = lib.getmetatable() // We can discuss if this should be a function or not
  case glua.call_function(lua, getmetatable, [table]) {
    Ok(#(lua, [metatable])) ->{
          // do stuff with metatable
          True
         }
        _ -> False
      }
  }
}

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