lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Generally, I would hesitate to unlurk on a mailing list with what
seems to be a newbie problem. However, I am relatively new to Lua and
even even though I have the manual and have read quite a bit of the
"Programming in Lua" online help I am still unable to find the aswer
to my problem. Perhaps there isn't a real answer. What I am hoping to
avoid is a generic answer or RTFM, which I was able to find all over
the internet via google searches and wiki studies.
Here is what I have thus far, and the comments should explain my problem:

-------------Begin Psuedo-Code--------------------
--Simple string stored in a table
t = { [[And this is from the Lua script!]] }
--End of script

C code:

struct user_data {
int uuid;			/* User's unique ID num			*/
char inbuf[8192];		/* Users's input buffer control		*/
char outbuf[8192];		/* Socket's output buffer control	*/

* c_to_user:
* Psuedo function that takes a variable (txt) and stores it in the
* "user's" outbuf for later processing.
void c_to_user(struct user_data *usr, char *txt) {

 /* Do some basic error checking... */
 if (!usr || !txt || txt[0] == '\0') { return; }

 /* Use 'sprintf' to store the input to the user's outbuf */
 sprintf(usr->outbuf, "%s", txt);


* lua_to_user:
* Run a lua script and send the output to c_to_user.
void lua_to_user(struct user_data *usr, char *txt, lua_State *L) {
 const char *s = NULL;
 char buf[8192];
 memset(buf, '\0', 8192);

 c_to_user(usr, "This is stored in C.");

 /* "txt" would be a !validated! path to the Lua script */
 luaL_dostring(L, txt);

 /* At this point my knowledge breaks down and I run out of ideas,
  * however this is the place I would call "lua_to_user" with the
  * script's output.

-------------  End Psuedo-Code--------------------

If anyone out there is able to figure out my problem, I would greatly
appreciate their response.

Thanks in advance,