Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7729045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:52:13+00:00 2026-06-01T05:52:13+00:00

How can I pass arguments to my lua dll function? I made a simple

  • 0

How can I pass arguments to my lua dll function?

I made a simple lua dll function:

static int functionName(lua_State *L, int arg1, char arg2[])
{
printf("running my dll:\n");
printf("passing number: %d   passing string = %s",arg1,arg2);
return 0;
}

And use this in lua to run the function:

require "myTestDll";
myTestDll.functionName(1231544,"Hello World, I'm running my DLL.");

But the result is that it prints the wrong number and not even close to the correct string.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:52:15+00:00Added an answer on June 1, 2026 at 5:52 am

    Functions you register to Lua must always have the same C or C++ signature: int FuncName(lua_State*); They can take no more or less parameters than that.

    Lua parameters passed to registered functions are part of the lua_State*. They are the first values placed on the Lua stack. So you can call lua_gettop to get the number of parameters. And you can use the usual Lua stack functions to pull them off of the stack.

    For example, if you want your function to have two parameters, where the first is a number and the second is a string, you do this:

    int functionName(lua_State *L)
    {
      int arg1 = 0;
      const char *arg2 = NULL;
      size_t arg2Len = 0; //Lua strings have an explicit length; they can contain null characters.
    
      if(lua_gettop(L) != 2)
      {
        lua_pushstring(L, "Must provide two parameters to this Lua function.");
        lua_error(L);
      }
    
      arg1 = luaL_checkinteger(L, 1);
      arg2 = luaL_checklstring(L, 2, &arg2Len);
    
      //Do stuff with arguments.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know you can pass arguments through the RunWorkerAsync function call when you first
Can i pass strings as arguments during method.Invoke(objectname,object[]params) for a method of signature Getdetails(int,string,bool)
How can I pass dynamic arguments to a function , e.g var customvar =
Can we pass arguments of different datatypes to same variadic function at the same
Is there any way that I can pass arguments in selector? example: I have
In Visual Studio Debug part, we can pass arguments. I want to know how
How can I pass back some arguments from a window that is closed? For
I noticed today that I can't use * to pass width or precision arguments
How can one pass multiple arguments along with an event object to an event
Can I pass variables to a GNU Makefile as command line arguments? In other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.