Pointer:as()method

Casts the current Pointer to the provided Pointer type.

Return value

The function returns a new Pointer pointing to the same memory address but casted to the provided C type.

Example

--! luart-extensions import c -- Creates a Pointer to a Buffer in memory (Pointer of type "void*") local buff = sys.Buffer("\x48\x65\x6C\x6C\x6F\x20\x4C\x75\x61\x52\x54\x20\x21\x00") local c_ptr = c.Pointer(buff) -- always false : we are comparing a memory pointer to a Lua string value print(c_ptr == "Hello LuaRT !") -- always true : converts the memory pointer to a Lua string value local lua_string = tostring(c_ptr:as("string")) -- c_ptr is casted to a "string" before print(lua_string == "Hello LuaRT !")