How can I create a pointer to existing data using the LuaJIT FFI?

Lucien Greathouse

I know there are examples of creating pointers using the LuaJIT FFI, but most of these aren't pointed to existing data. One such example of this is here: How to pass a pointer to LuaJIT ffi to be used as out argument?

One thing that I haven't been able to successfully do is create a pointer to an existing value. In order to have a pointer type as far as I know, I have to know that I want to have a pointer point to it at some point in the future, as in:

local vao = ffi.new("GLuint[1]")
gl.GenVertexArrays(1, vao)
gl.BindVertexArray(vao[0])

Here, I know that glGenVertexArrays needs a pointer to vao, so I specify it as a GLuint[1]. In C, I would be doing something like the following:

GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

Here, I have no idea that I'll be needing a pointer to vao, so I can just specify it normally.

In other words, is there a way to get the address of, or create a pointer to, an existing value? Do I have to foresee what I'll be doing with the value before I create it?

Thanks!

Colonel Thirty Two

There's no way to get a pointer to a cdata object in the FFI.

I remember reading in the LuaJIT mailing list that this was done intentionally for some optimizations to work, though I can't find the exact message in the archive.

So far, I haven't had a need for getting the pointer of a cdata object; LuaJIT refers to cdata by reference (similar to tables) and the type[1] trick works for out parameters.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how can I create new XML file from existing database in PostgreSQL database using java

How can I create "C Blocks" when using FFI?

How can I click using ffi in NodeJS?

Can I pass a ruby object pointer to a ruby-ffi callback?

How do I make an FFI call with a char** pointer?

How do I make a struct for FFI that contains a nullable function pointer?

How can I create multiple shades in dygraphs using a data frame?

How can I create a Mongo index definition from an existing one using the C# driver?

How can I create a table using factor data

How can I create a Work Item linked to existing item using DevOps rest api?

How can I create an interactive list using MySql data in python

How do I assign a pointer to a record element using an existing pointer?

RegGetValueA hard crashing application using luajit ffi

I'm using the Slugalicious gem. How do I create slugs for existing data in my database?

In trepl or luajit, how can I find the source code of a library I'm using?

FFI Encryption/Decryption with LuaJit

How to create TreeSet using an existing HashSet with data in it?

How can I create rows of data using jquery append()?

How can i fetch data from django models(database) using celery(asynchronously) from previously existing data

How to access a C_POINTER in a MemoryLayout using Java Panama FFI

How can I create an instance of an entity that has @GeneratedValue to insert mock data without updating existing rows?

How can I create a data frame with all existing variables (at once)?

How can I create a column in an existing df from dictionary and using conditions?

R - How can i create graphs using an Aggregate data table?

How can I create a new data frame based on the existing columns?

How can I add data to an existing PowerPoint presentation using Node?

How can i create a new file using FileStream without overwriting existing?

How to create a pointer to a dart function that takes a String in dart:ffi?

How can I get char* using lua ffi